Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Optional typehint usage in typehint files #2678

Merged
merged 2 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions buildconfig/pygame-stubs/bufferproxy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ class BufferProxy(object):
raw: bytes
else:
raw: str

@overload
def __init__(self) -> None: ...
@overload
def __init__(self, parent: Any) -> None: ...
def write(self, buffer: bytes, offset: Optional[int] = 0) -> None: ...
def write(self, buffer: bytes, offset: int = 0) -> None: ...
10 changes: 5 additions & 5 deletions buildconfig/pygame-stubs/camera.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ class Camera:
def __init__(
self,
device: str,
size: Optional[Union[Tuple[int, int], List[int]]] = (320, 200),
format: Optional[str] = "RGB",
size: Union[Tuple[int, int], List[int]] = (640, 480),
format: str = "RGB",
) -> None: ...
def start(self) -> None: ...
def stop(self) -> None: ...
def get_controls(self) -> Tuple[bool, bool, int]: ...
def set_controls(
self,
hflip: Optional[bool] = ...,
vflip: Optional[bool] = ...,
brightness: Optional[int] = ...,
hflip: bool = ...,
vflip: bool = ...,
brightness: int = ...,
) -> Tuple[bool, bool, int]: ...
def get_size(self) -> Tuple[int, int]: ...
def query_image(self) -> bool: ...
Expand Down
4 changes: 2 additions & 2 deletions buildconfig/pygame-stubs/color.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Color:
i1i2i3: Tuple[float, float, float]
__hash__: None # type: ignore
@overload
def __init__(self, r: int, g: int, b: int, a: Optional[int] = ...) -> None: ...
def __init__(self, r: int, g: int, b: int, a: int = ...) -> None: ...
ankith26 marked this conversation as resolved.
Show resolved Hide resolved
@overload
def __init__(self, rgbvalue: _ColorValue) -> None: ...
@overload
Expand All @@ -34,6 +34,6 @@ class Color:
def lerp(self, color: _ColorValue, amount: float) -> Color: ...
def premul_alpha(self) -> Color: ...
@overload
def update(self, r:int, g: int, b: int, a: Optional[int] = ...) -> None: ...
def update(self, r: int, g: int, b: int, a: int = ...) -> None: ...
@overload
def update(self, rgbvalue: _ColorValue) -> None: ...
57 changes: 28 additions & 29 deletions buildconfig/pygame-stubs/cursors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,40 @@ sizer_xy_strings: _Small_string

def compile(
strings: Sequence[str],
black: Optional[str] = "X",
white: Optional[str] = ".",
xor: Optional[str] = "o",
black: str = "X",
white: str = ".",
xor: str = "o",
) -> Tuple[Sequence[int], Sequence[int]]: ...


def load_xbm(cursorfile: str, maskfile: str) -> Tuple[
List[int],
List[int],
Tuple[int, ...],
Tuple[int, ...]
]: ...

def load_xbm(
cursorfile: str, maskfile: str
) -> Tuple[List[int], List[int], Tuple[int, ...], Tuple[int, ...]]: ...

class Cursor(Iterable[object]):
@overload
def __init__(self, constant: int) -> None: ...
@overload
def __init__(self, size: Union[Tuple[int, int], List[int]],
hotspot: Union[Tuple[int, int], List[int]],
xormasks: Sequence[int],
andmasks: Sequence[int],
) -> None: ...
def __init__(
self,
size: Union[Tuple[int, int], List[int]],
hotspot: Union[Tuple[int, int], List[int]],
xormasks: Sequence[int],
andmasks: Sequence[int],
) -> None: ...
@overload
def __init__(self, hotspot: Union[Tuple[int, int], List[int]],
surface: Surface,
) -> None: ...

def __init__(
self,
hotspot: Union[Tuple[int, int], List[int]],
surface: Surface,
) -> None: ...
def __iter__(self) -> Iterator[object]: ...

type: str
data: Union[Tuple[int],
Tuple[Union[Tuple[int, int], List[int]],
Union[Tuple[int, int], List[int]],
Sequence[int],
Sequence[int]],
Tuple[int, Surface]]

data: Union[
Tuple[int],
Tuple[
Union[Tuple[int, int], List[int]],
Union[Tuple[int, int], List[int]],
Sequence[int],
Sequence[int],
],
Tuple[int, Surface],
]
38 changes: 19 additions & 19 deletions buildconfig/pygame-stubs/display.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ from pygame.constants import FULLSCREEN
_Coordinate = Union[Tuple[float, float], List[float], Vector2]
_CanBeRect = Union[
Rect,
Tuple[int, int, int, int], List[int],
Tuple[_Coordinate, _Coordinate], List[_Coordinate]
Tuple[int, int, int, int],
List[int],
Tuple[_Coordinate, _Coordinate],
List[_Coordinate],
]

class _HasRectAttribute(Protocol):
rect: _CanBeRect
_RectValue = Union[
_CanBeRect, _HasRectAttribute
]

_RectValue = Union[_CanBeRect, _HasRectAttribute]
_ColorValue = Union[
Color, int, Tuple[int, int, int], Tuple[int, int, int, int], List[int]
]
Expand All @@ -44,11 +46,11 @@ def init() -> None: ...
def quit() -> None: ...
def get_init() -> bool: ...
def set_mode(
size: Optional[_Coordinate],
flags: Optional[int] = 0,
depth: Optional[int] = 0,
display: Optional[int] = 0,
vsync: Optional[int] = 0
size: _Coordinate = (0, 0),
flags: int = 0,
depth: int = 0,
display: int = 0,
vsync: int = 0,
) -> Surface: ...
def get_surface() -> Surface: ...
def flip() -> None: ...
Expand All @@ -57,24 +59,22 @@ def get_driver() -> str: ...
def Info() -> _VidInfo: ...
def get_wm_info() -> Dict[str, int]: ...
def list_modes(
depth: Optional[int] = 0,
flags: Optional[int] = FULLSCREEN,
display: Optional[int] = 0,
depth: int = 0,
flags: int = FULLSCREEN,
display: int = 0,
) -> List[Tuple[int, int]]: ...
def mode_ok(
size: Union[Sequence[int], Tuple[int, int]],
flags: Optional[int] = 0,
depth: Optional[int] = 0,
display: Optional[int] = 0,
flags: int = 0,
depth: int = 0,
display: int = 0,
) -> int: ...
def gl_get_attribute(flag: int) -> int: ...
def gl_set_attribute(flag: int, value: int) -> None: ...
def get_active() -> bool: ...
def iconify() -> bool: ...
def toggle_fullscreen() -> int: ...
def set_gamma(
red: float, green: Optional[float] = None, blue: Optional[float] = None
) -> int: ...
def set_gamma(red: float, green: float = ..., blue: float = ...) -> int: ...
def set_gamma_ramp(
red: Sequence[int], green: Sequence[int], blue: Sequence[int]
) -> int: ...
Expand Down
40 changes: 21 additions & 19 deletions buildconfig/pygame-stubs/draw.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,81 @@ _ColorValue = Union[
]
_CanBeRect = Union[
Rect,
Tuple[int, int, int, int], List[int],
Tuple[_Coordinate, _Coordinate], List[_Coordinate]
Tuple[int, int, int, int],
List[int],
Tuple[_Coordinate, _Coordinate],
List[_Coordinate],
]

class _HasRectAttribute(Protocol):
rect: _CanBeRect
_RectValue = Union[
_CanBeRect, _HasRectAttribute
]

_RectValue = Union[_CanBeRect, _HasRectAttribute]

def rect(
surface: Surface,
color: _ColorValue,
rect: _RectValue,
width: Optional[int] = 0,
border_radius: Optional[int] = -1,
border_top_left_radius: Optional[int] = -1,
border_top_right_radius: Optional[int] = -1,
border_bottom_left_radius: Optional[int] = -1,
border_bottom_right_radius: Optional[int] = -1,
width: int = 0,
border_radius: int = -1,
border_top_left_radius: int = -1,
border_top_right_radius: int = -1,
border_bottom_left_radius: int = -1,
border_bottom_right_radius: int = -1,
) -> Rect: ...
def polygon(
surface: Surface,
color: _ColorValue,
points: Sequence[_Coordinate],
width: Optional[int] = 0,
width: int = 0,
) -> Rect: ...
def circle(
surface: Surface,
color: _ColorValue,
center: _Coordinate,
radius: float,
width: Optional[int] = 0,
width: int = 0,
draw_top_right: Optional[bool] = None,
draw_top_left: Optional[bool] = None,
draw_bottom_left: Optional[bool] = None,
draw_bottom_right: Optional[bool] = None,
) -> Rect: ...
def ellipse(
surface: Surface, color: _ColorValue, rect: _RectValue, width: Optional[int] = 0
surface: Surface, color: _ColorValue, rect: _RectValue, width: int = 0
) -> Rect: ...
def arc(
surface: Surface,
color: _ColorValue,
rect: _RectValue,
start_angle: float,
stop_angle: float,
width: Optional[int] = 1,
width: int = 1,
) -> Rect: ...
def line(
surface: Surface,
color: _ColorValue,
start_pos: _Coordinate,
end_pos: _Coordinate,
width: Optional[int] = 1,
width: int = 1,
) -> Rect: ...
def lines(
surface: Surface,
color: _ColorValue,
closed: bool,
points: Sequence[_Coordinate],
width: Optional[int] = 1,
width: int = 1,
) -> Rect: ...
def aaline(
surface: Surface,
color: _ColorValue,
start_pos: _Coordinate,
end_pos: _Coordinate,
blend: Optional[int] = 1,
blend: int = 1,
) -> Rect: ...
def aalines(
surface: Surface,
color: _ColorValue,
closed: bool,
points: Sequence[_Coordinate],
blend: Optional[int] = 1,
blend: int = 1,
) -> Rect: ...
10 changes: 5 additions & 5 deletions buildconfig/pygame-stubs/font.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from typing import Any, List, Optional, Union, Tuple, IO, Hashable, Iterable

if sys.version_info >= (3, 6):
from os import PathLike

AnyPath = Union[str, bytes, PathLike[str], PathLike[bytes]]
else:
AnyPath = Union[Text, bytes]
Expand All @@ -21,22 +22,21 @@ def get_default_font() -> str: ...
def get_fonts() -> List[str]: ...
def match_font(
name: Union[str, bytes, Iterable[Union[str, bytes]]],
bold: Optional[Hashable] = False,
italic: Optional[Hashable] = False
bold: Hashable = False,
italic: Hashable = False,
) -> str: ...
def SysFont(
name: Union[str, bytes, Iterable[Union[str, bytes]]],
size: int,
bold: Optional[Hashable] = False,
italic: Optional[Hashable] = False,
bold: Hashable = False,
italic: Hashable = False,
) -> Font: ...

class Font(object):

bold: bool
italic: bool
underline: bool

def __init__(self, name: Union[AnyPath, IO[Any], None], size: int) -> None: ...
def render(
self,
Expand Down