Skip to content

Commit 011162a

Browse files
authored
Merge pull request #3335 from aatle/typing-fixes
General improvements and fixes to stubs
1 parent b0f35bc commit 011162a

File tree

20 files changed

+110
-72
lines changed

20 files changed

+110
-72
lines changed

buildconfig/stubs/pygame/_sdl2/controller.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def get_init() -> bool: ...
66
def quit() -> None: ...
77
def is_controller(device_index: int) -> bool: ...
88
def get_count() -> int: ...
9+
910
@final
1011
class Controller:
1112
def __new__(cls, device_index: int) -> Controller: ...

buildconfig/stubs/pygame/_sdl2/touch.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import TypedDict, Optional
22

3-
# dict at runtime, this only exist for benefit of the typechecker
43
class _FingerDict(TypedDict):
54
id: int
65
x: float
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
from typing import Any, overload
1+
from typing import Any
22

33
class BufferProxy:
4-
parent: Any
5-
length: int
6-
raw: bytes
4+
@property
5+
def parent(self) -> Any: ...
6+
@property
7+
def length(self) -> int: ...
8+
@property
9+
def raw(self) -> bytes: ...
710
# possibly going to be deprecated/removed soon, in which case these
811
# typestubs must be removed too
9-
__array_interface__: dict[str, Any]
10-
__array_struct__: Any
11-
@overload
12-
def __init__(self) -> None: ...
13-
@overload
14-
def __init__(self, parent: Any) -> None: ...
12+
@property
13+
def __array_interface__(self) -> dict[str, Any]: ...
14+
@property
15+
def __array_struct__(self) -> Any: ...
16+
def __init__(self, parent: Any) -> None: ... # TODO: parent: TypedDict | Protocol
1517
def write(self, buffer: bytes, offset: int = 0) -> None: ...

buildconfig/stubs/pygame/color.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Collection, Iterator
2-
from typing import Any, SupportsIndex, Union, overload
2+
from typing import Any, ClassVar, SupportsIndex, Union, overload
33
from typing_extensions import deprecated # added in 3.13
44

55
from pygame.typing import ColorLike
@@ -18,8 +18,9 @@ class Color(Collection[int]):
1818
hsla: tuple[float, float, float, float]
1919
i1i2i3: tuple[float, float, float]
2020
normalized: tuple[float, float, float, float]
21-
__hash__: None # type: ignore
22-
__array_struct__: Any
21+
__hash__: ClassVar[None] # type: ignore[assignment]
22+
@property
23+
def __array_struct__(self) -> Any: ...
2324
@overload
2425
def __init__(self, r: int, g: int, b: int, a: int = 255) -> None: ...
2526
@overload
@@ -41,8 +42,8 @@ class Color(Collection[int]):
4142
def __index__(self) -> int: ...
4243
def __invert__(self) -> Color: ...
4344
def __contains__(self, other: int) -> bool: ... # type: ignore[override]
44-
def __getattribute__(self, attr: str) -> Union[Color, tuple[int, ...]]: ...
45-
def __setattr__(self, attr: str, value: Union[Color, tuple[int, ...]]) -> None: ...
45+
def __getattribute__(self, name: str) -> Union[Color, tuple[int, ...]]: ...
46+
def __setattr__(self, name: str, value: Union[Color, tuple[int, ...]]) -> None: ...
4647
@overload
4748
@classmethod
4849
def from_cmy(cls, object: tuple[float, float, float], /) -> Color: ...

buildconfig/stubs/pygame/display.pyi

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,40 @@ from pygame.typing import (
1616
)
1717

1818
class _VidInfo:
19-
hw: int
20-
wm: int
21-
video_mem: int
22-
bitsize: int
23-
bytesize: int
24-
masks: tuple[int, int, int, int]
25-
shifts: tuple[int, int, int, int]
26-
losses: tuple[int, int, int, int]
27-
blit_hw: int
28-
blit_hw_CC: int
29-
blit_hw_A: int
30-
blit_sw: int
31-
blit_sw_CC: int
32-
blit_sw_A: int
33-
current_h: int
34-
current_w: int
35-
pixel_format: str
19+
@property
20+
def hw(self) -> int: ...
21+
@property
22+
def wm(self) -> int: ...
23+
@property
24+
def video_mem(self) -> int: ...
25+
@property
26+
def bitsize(self) -> int: ...
27+
@property
28+
def bytesize(self) -> int: ...
29+
@property
30+
def masks(self) -> tuple[int, int, int, int]: ...
31+
@property
32+
def shifts(self) -> tuple[int, int, int, int]: ...
33+
@property
34+
def losses(self) -> tuple[int, int, int, int]: ...
35+
@property
36+
def blit_hw(self) -> int: ...
37+
@property
38+
def blit_hw_CC(self) -> int: ...
39+
@property
40+
def blit_hw_A(self) -> int: ...
41+
@property
42+
def blit_sw(self) -> int: ...
43+
@property
44+
def blit_sw_CC(self) -> int: ...
45+
@property
46+
def blit_sw_A(self) -> int: ...
47+
@property
48+
def current_h(self) -> int: ...
49+
@property
50+
def current_w(self) -> int: ...
51+
@property
52+
def pixel_format(self) -> str: ...
3653

3754
def init() -> None: ...
3855
def quit() -> None: ...

buildconfig/stubs/pygame/event.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Union, final
1+
from typing import Any, ClassVar, Optional, Union, final
22
from typing_extensions import deprecated # added in 3.13
33

44
from pygame.typing import SequenceLike
@@ -10,11 +10,11 @@ class _GenericEvent:
1010
@property
1111
def type(self) -> int: ...
1212
__dict__: dict[str, Any]
13-
__hash__: None # type: ignore
13+
__hash__: ClassVar[None] # type: ignore[assignment]
1414
def __init__(
1515
self, type: int, dict: dict[str, Any] = ..., **kwargs: Any
1616
) -> None: ...
17-
def __getattribute__(self, name: str) -> Any: ...
17+
def __getattr__(self, name: str) -> Any: ...
1818
def __setattr__(self, name: str, value: Any) -> None: ...
1919
def __delattr__(self, name: str) -> None: ...
2020
def __bool__(self) -> bool: ...

buildconfig/stubs/pygame/image.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ from pygame.surface import Surface
66

77
from pygame.typing import FileLike, IntPoint, Point
88

9-
_BufferStyle = Union[BufferProxy, bytes, bytearray, memoryview]
9+
_BufferLike = Union[BufferProxy, bytes, bytearray, memoryview]
10+
_from_buffer_format = Literal["P", "RGB", "BGR", "BGRA", "RGBX", "RGBA", "ARGB"]
1011
_to_bytes_format = Literal[
1112
"P", "RGB", "RGBX", "RGBA", "ARGB", "BGRA", "ABGR", "RGBA_PREMULT", "ARGB_PREMULT"
1213
]
13-
_from_buffer_format = Literal["P", "RGB", "BGR", "BGRA", "RGBX", "RGBA", "ARGB"]
1414
_from_bytes_format = Literal["P", "RGB", "RGBX", "RGBA", "ARGB", "BGRA", "ABGR"]
1515

1616
def load(file: FileLike, namehint: str = "") -> Surface: ...
@@ -47,7 +47,7 @@ def frombytes(
4747
pitch: int = -1,
4848
) -> Surface: ...
4949
def frombuffer(
50-
bytes: _BufferStyle,
50+
buffer: _BufferLike,
5151
size: IntPoint,
5252
format: _from_buffer_format,
5353
pitch: int = -1,

buildconfig/stubs/pygame/joystick.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def init() -> None: ...
55
def quit() -> None: ...
66
def get_init() -> bool: ...
77
def get_count() -> int: ...
8+
89
@final
910
class JoystickType:
1011
def __init__(self, id: int) -> None: ...

buildconfig/stubs/pygame/key.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from typing import NoReturn
2+
13
from pygame.typing import RectLike
24

3-
class ScancodeWrapper(tuple[bool, ...]): ...
5+
class ScancodeWrapper(tuple[bool, ...]):
6+
def __iter__(self) -> NoReturn: ...
47

58
def get_focused() -> bool: ...
69
def get_pressed() -> ScancodeWrapper: ...

buildconfig/stubs/pygame/math.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections.abc import Collection, Iterator
22
from typing import (
33
Any,
4+
ClassVar,
45
Generic,
56
Literal,
67
SupportsIndex,
@@ -23,7 +24,7 @@ _TVec = TypeVar("_TVec", bound=_GenericVector)
2324
# Also used with _TVec generics
2425
class _GenericVector(Collection[float]):
2526
epsilon: float
26-
__hash__: None # type: ignore
27+
__hash__: ClassVar[None] # type: ignore[assignment]
2728
def __len__(self) -> int: ...
2829
@overload
2930
def __setitem__(self, key: int, value: float) -> None: ...

0 commit comments

Comments
 (0)