Skip to content

Commit

Permalink
Merge pull request #1729 from MightyJosip/stubs
Browse files Browse the repository at this point in the history
Some type hint fixes
  • Loading branch information
Dan Lawrence committed May 14, 2020
2 parents b192ca0 + 715d2f4 commit 6df1c80
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
1 change: 0 additions & 1 deletion buildconfig/pygame-stubs/__init__.pyi
Expand Up @@ -42,7 +42,6 @@ class PixelArray(pygame.pixelarray.PixelArray): ...
class Vector2(pygame.math.Vector2): ...
class Vector3(pygame.math.Vector3): ...


def init() -> Tuple[int, int]: ...
def quit() -> None: ...
def get_init() -> bool: ...
Expand Down
4 changes: 2 additions & 2 deletions buildconfig/pygame-stubs/font.pyi
@@ -1,4 +1,4 @@
from typing import List, Optional, Union, Tuple
from typing import List, Optional, Union, Tuple, IO

from pygame.color import Color
from pygame.surface import Surface
Expand All @@ -20,7 +20,7 @@ def SysFont(
) -> Font: ...

class Font(object):
def __init__(self, name: Union[str, None], size: int) -> None: ...
def __init__(self, name: Union[str, IO, None], size: int) -> None: ...
def render(
self,
text: str,
Expand Down
4 changes: 2 additions & 2 deletions buildconfig/pygame-stubs/image.pyi
@@ -1,8 +1,8 @@
from typing import Optional, Tuple, List, Union
from typing import Optional, Tuple, List, Union, IO

from pygame.surface import Surface

def load(filename: str, namehint: Optional[str] = "") -> Surface: ...
def load(filename: Union[str, IO], namehint: Optional[str] = "") -> Surface: ...
def save(surface: Surface, filename: str) -> None: ...
def get_extended() -> bool: ...
def tostring(surface: Surface, format: str, flipped: Optional[bool] = False) -> str: ...
Expand Down
2 changes: 1 addition & 1 deletion buildconfig/pygame-stubs/key.pyi
Expand Up @@ -13,7 +13,7 @@ def get_focused() -> bool: ...
def get_pressed() -> Sequence[bool]: ...
def get_mods() -> int: ...
def set_mods() -> int: ...
def set_repeat(delay: Optional[int], interval: Optional[int]) -> None: ...
def set_repeat(delay: Optional[int] = 0, interval: Optional[int] = 0) -> None: ...
def get_repeat() -> Tuple[int, int]: ...
def name(key: int) -> str: ...
def key_code(name: str) -> int: ...
Expand Down
4 changes: 4 additions & 0 deletions buildconfig/pygame-stubs/rect.pyi
Expand Up @@ -52,6 +52,10 @@ class Rect(object):
self,
left_top_width_height: Union[Tuple[float, float, float, float], List[float]],
) -> None: ...
@overload
def __getitem__(self, i: int) -> int: ...
@overload
def __getitem__(self, s: slice) -> List[int]: ...
def copy(self) -> Rect: ...
def move(self, x: float, y: float) -> Rect: ...
def move_ip(self, x: float, y: float) -> None: ...
Expand Down
28 changes: 20 additions & 8 deletions buildconfig/pygame-stubs/sprite.pyi
@@ -1,4 +1,14 @@
from typing import List, Dict, Any, Union, Tuple, Optional, Callable, SupportsFloat
from typing import (
List,
Dict,
Any,
Union,
Tuple,
Optional,
Callable,
SupportsFloat,
Iterator,
)

from pygame.rect import Rect
from pygame.surface import Surface
Expand All @@ -14,29 +24,31 @@ _RectStyle = Union[
# best type hints I could do

class Sprite:
image: Surface
rect: Rect
def __init__(self, *groups: Group) -> None: ...
image: Optional[Surface] = None
rect: Optional[Rect] = None
def __init__(self, *groups: AbstractGroup) -> None: ...
def update(self, *args, **kwargs) -> None: ...
def add(self, *groups: Group) -> None: ...
def remove(self, *groups: Group) -> None: ...
def add(self, *groups: AbstractGroup) -> None: ...
def remove(self, *groups: AbstractGroup) -> None: ...
def kill(self) -> None: ...
def alive(self) -> bool: ...
def groups(self) -> List[Group]: ...
def groups(self) -> List[AbstractGroup]: ...

class DirtySprite(Sprite):
dirty: int
blendmode: int
source_rect: Rect
visible: int
layer: int
_layer: int
def _set_visible(self, value: int) -> None: ...
def _get_visible(self) -> int: ...

class AbstractGroup:
spritedict = Dict[Sprite, int]
lostsprites = List[int] # I think
def __init__(self) -> None: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[Sprite]: ...
def copy(self) -> AbstractGroup: ...
def sprites(self) -> List[Sprite]: ...
def add(self, *sprites: Sprite) -> None: ...
Expand Down
6 changes: 4 additions & 2 deletions buildconfig/pygame-stubs/surface.pyi
Expand Up @@ -10,28 +10,30 @@ _ColorInput = Union[
]
_RgbaOutput = Tuple[int, int, int, int]
_RectStyle = Union[
Rect,
Tuple[float, float, float, float],
Tuple[Tuple[float, float], Tuple[float, float]],
List[float],
List[Vector2],
Tuple[Vector2, Vector2],
Iterable[Vector2],
]
_Coordinate = Union[Tuple[float, float], List[float], Vector2]

class Surface(object):
_pixels_address: int
@overload
def __init__(
self,
width_height: Tuple[float, float],
size: _Coordinate,
flags: int = ...,
depth: int = ...,
masks: Optional[_ColorInput] = ...,
) -> None: ...
@overload
def __init__(
self,
width_height: Tuple[float, float],
size: _Coordinate,
flags: int = ...,
surface: Surface = ...,
) -> None: ...
Expand Down

0 comments on commit 6df1c80

Please sign in to comment.