Skip to content

Commit 4b6bb5e

Browse files
committed
Modernise code to use python 3.10 features
1 parent 1fba232 commit 4b6bb5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+325
-367
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from collections.abc import Callable
2-
from typing import Optional, Union
32

4-
ImportResult = tuple[str, bool, Optional[Callable]]
5-
6-
def str_from_tuple(version_tuple: Union[tuple[int, int, int], None]) -> str: ...
3+
def str_from_tuple(version_tuple: tuple[int, int, int] | None) -> str: ...
74
def attempt_import(
85
module: str, function_name: str, output_str: str = ""
9-
) -> ImportResult: ...
10-
def print_debug_info(filename: Optional[str] = None) -> None: ...
6+
) -> tuple[str, bool, Callable | None]: ...
7+
def print_debug_info(filename: str | None = None) -> None: ...

buildconfig/stubs/pygame/_render.pyi

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Iterable
2-
from typing import Any, Optional, Protocol, Union, final
2+
from typing import Any, Protocol, final
33

44
from pygame.color import Color
55
from pygame.rect import Rect
@@ -9,9 +9,7 @@ from pygame.window import Window
99

1010
class _DrawableClass(Protocol):
1111
# Object that has the draw method that accepts area and dest arguments
12-
def draw(
13-
self, area: Optional[RectLike] = None, dest: Optional[RectLike] = None
14-
): ...
12+
def draw(self, area: RectLike | None = None, dest: RectLike | None = None): ...
1513

1614
@final
1715
class Renderer:
@@ -25,9 +23,9 @@ class Renderer:
2523
) -> None: ...
2624
def blit(
2725
self,
28-
source: Union["Texture", "Image", _DrawableClass],
29-
dest: Optional[RectLike] = None,
30-
area: Optional[RectLike] = None,
26+
source: "Texture" | "Image" | _DrawableClass,
27+
dest: RectLike | None = None,
28+
area: RectLike | None = None,
3129
special_flags: int = 0,
3230
) -> Rect: ...
3331
def clear(self) -> None: ...
@@ -43,9 +41,9 @@ class Renderer:
4341
def coordinates_to_window(self, point: Point) -> tuple[float, float]: ...
4442
def coordinates_from_window(self, point: Point) -> tuple[float, float]: ...
4543
def present(self) -> None: ...
46-
def set_viewport(self, area: Optional[RectLike]) -> None: ...
44+
def set_viewport(self, area: RectLike | None) -> None: ...
4745
def to_surface(
48-
self, surface: Optional[Surface] = None, area: Optional[RectLike] = None
46+
self, surface: Surface | None = None, area: RectLike | None = None
4947
) -> Surface: ...
5048
@property
5149
def draw_blend_mode(self) -> int: ...
@@ -84,7 +82,7 @@ class Texture:
8482
static: bool = False,
8583
streaming: bool = False,
8684
target: bool = False,
87-
scale_quality: Optional[int] = None,
85+
scale_quality: int | None = None,
8886
) -> None: ...
8987
@property
9088
def alpha(self) -> int: ...
@@ -108,10 +106,10 @@ class Texture:
108106
def from_surface(cls, renderer: Renderer, surface: Surface) -> Texture: ...
109107
def draw(
110108
self,
111-
srcrect: Optional[RectLike] = None,
112-
dstrect: Optional[RectLike] = None,
109+
srcrect: RectLike | None = None,
110+
dstrect: RectLike | None = None,
113111
angle: float = 0.0,
114-
origin: Optional[Iterable[int]] = None,
112+
origin: Iterable[int] | None = None,
115113
flip_x: bool = False,
116114
flip_y: bool = False,
117115
) -> None: ...
@@ -143,7 +141,7 @@ class Texture:
143141
p4_mod: ColorLike = (255, 255, 255, 255),
144142
) -> None: ...
145143
def get_rect(self, **kwargs: Any) -> Rect: ...
146-
def update(self, surface: Surface, area: Optional[RectLike] = None) -> None: ...
144+
def update(self, surface: Surface, area: RectLike | None = None) -> None: ...
147145

148146
@final
149147
class Image:

buildconfig/stubs/pygame/_sdl2/controller_old.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections.abc import Mapping
2-
from typing import Optional
32

43
from pygame.joystick import JoystickType
54

@@ -11,7 +10,7 @@ def get_eventstate() -> bool: ...
1110
def update() -> None: ...
1211
def get_count() -> int: ...
1312
def is_controller(index: int) -> bool: ...
14-
def name_forindex(index: int) -> Optional[str]: ...
13+
def name_forindex(index: int) -> str | None: ...
1514

1615
class Controller:
1716
def __init__(self, index: int) -> None: ...

buildconfig/stubs/pygame/_sdl2/sdl2.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
INIT_TIMER: int
42
INIT_AUDIO: int
53
INIT_VIDEO: int
@@ -11,6 +9,6 @@ INIT_NOPARACHUTE: int
119
INIT_EVERYTHING: int
1210

1311
class error(RuntimeError):
14-
def __init__(self, message: Optional[str] = None) -> None: ...
12+
def __init__(self, message: str | None = None) -> None: ...
1513

1614
def init_subsystem(flags: int) -> None: ...

buildconfig/stubs/pygame/_sdl2/touch.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, TypedDict
1+
from typing import TypedDict
22

33
class _FingerDict(TypedDict):
44
id: int
@@ -9,4 +9,4 @@ class _FingerDict(TypedDict):
99
def get_num_devices() -> int: ...
1010
def get_device(index: int, /) -> int: ...
1111
def get_num_fingers(device_id: int, /) -> int: ...
12-
def get_finger(touchid: int, index: int) -> Optional[_FingerDict]: ...
12+
def get_finger(touchid: int, index: int) -> _FingerDict | None: ...

buildconfig/stubs/pygame/_sdl2/video.pyi

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Generator, Iterable
2-
from typing import Any, Optional, Union
2+
from typing import Any
33

44
from pygame.color import Color
55
from pygame.rect import Rect
@@ -26,11 +26,11 @@ class RendererDriverInfo:
2626
max_texture_height: int
2727

2828
def get_drivers() -> Generator[RendererDriverInfo, None, None]: ...
29-
def get_grabbed_window() -> Optional[Window]: ...
29+
def get_grabbed_window() -> Window | None: ...
3030
def messagebox(
3131
title: str,
3232
message: str,
33-
window: Optional[Window] = None,
33+
window: Window | None = None,
3434
info: bool = False,
3535
warn: bool = False,
3636
error: bool = False,
@@ -48,7 +48,7 @@ class Texture:
4848
static: bool = False,
4949
streaming: bool = False,
5050
target: bool = False,
51-
scale_quality: Optional[int] = None,
51+
scale_quality: int | None = None,
5252
) -> None: ...
5353
@staticmethod
5454
def from_surface(renderer: Renderer, surface: Surface) -> Texture: ...
@@ -65,10 +65,10 @@ class Texture:
6565
def get_rect(self, **kwargs: Any) -> Rect: ...
6666
def draw(
6767
self,
68-
srcrect: Optional[RectLike] = None,
69-
dstrect: Optional[RectLike] = None,
68+
srcrect: RectLike | None = None,
69+
dstrect: RectLike | None = None,
7070
angle: float = 0.0,
71-
origin: Optional[Iterable[int]] = None,
71+
origin: Iterable[int] | None = None,
7272
flip_x: bool = False,
7373
flip_y: bool = False,
7474
) -> None: ...
@@ -99,20 +99,20 @@ class Texture:
9999
p3_mod: Iterable[int] = (255, 255, 255, 255),
100100
p4_mod: Iterable[int] = (255, 255, 255, 255),
101101
) -> None: ...
102-
def update(self, surface: Surface, area: Optional[RectLike] = None) -> None: ...
102+
def update(self, surface: Surface, area: RectLike | None = None) -> None: ...
103103

104104
class Image:
105105
def __init__(
106106
self,
107-
texture_or_image: Union[Texture, Image],
108-
srcrect: Optional[RectLike] = None,
107+
texture_or_image: Texture | Image,
108+
srcrect: RectLike | None = None,
109109
) -> None: ...
110110
def get_rect(self) -> Rect: ...
111111
def draw(
112-
self, srcrect: Optional[RectLike] = None, dstrect: Optional[RectLike] = None
112+
self, srcrect: RectLike | None = None, dstrect: RectLike | None = None
113113
) -> None: ...
114114
angle: float
115-
origin: Optional[Iterable[float]]
115+
origin: Iterable[float] | None
116116
flip_x: bool
117117
flip_y: bool
118118
alpha: float
@@ -144,17 +144,17 @@ class Renderer:
144144
def clear(self) -> None: ...
145145
def present(self) -> None: ...
146146
def get_viewport(self) -> Rect: ...
147-
def set_viewport(self, area: Optional[RectLike]) -> None: ...
147+
def set_viewport(self, area: RectLike | None) -> None: ...
148148
logical_size: Iterable[int]
149149
def coordinates_to_window(self, point: Point) -> tuple[float, float]: ...
150150
def coordinates_from_window(self, point: Point) -> tuple[float, float]: ...
151151
scale: Iterable[float]
152-
target: Optional[Texture]
152+
target: Texture | None
153153
def blit(
154154
self,
155-
source: Union[Texture, Image],
156-
dest: Optional[RectLike] = None,
157-
area: Optional[RectLike] = None,
155+
source: Texture | Image,
156+
dest: RectLike | None = None,
157+
area: RectLike | None = None,
158158
special_flags: int = 0,
159159
) -> Rect: ...
160160
def draw_line(self, p1: Point, p2: Point) -> None: ...
@@ -166,7 +166,7 @@ class Renderer:
166166
def draw_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
167167
def fill_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
168168
def to_surface(
169-
self, surface: Optional[Surface] = None, area: Optional[RectLike] = None
169+
self, surface: Surface | None = None, area: RectLike | None = None
170170
) -> Surface: ...
171171
@staticmethod
172172
def compose_custom_blend_mode(

buildconfig/stubs/pygame/camera.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from abc import ABC, abstractmethod
2-
from typing import Literal, Optional, Union
2+
from typing import Literal
33

44
from pygame.surface import Surface
55
from pygame.typing import IntPoint
66

77
def get_backends() -> list[str]: ...
8-
def init(backend: Optional[str] = None) -> None: ...
8+
def init(backend: str | None = None) -> None: ...
99
def quit() -> None: ...
1010
def list_cameras() -> list[str]: ...
1111
def colorspace(
@@ -24,7 +24,7 @@ class AbstractCamera(ABC):
2424
@abstractmethod
2525
def query_image(self) -> bool: ...
2626
@abstractmethod
27-
def get_image(self, dest_surf: Optional[Surface] = None) -> Surface: ...
27+
def get_image(self, dest_surf: Surface | None = None) -> Surface: ...
2828
@abstractmethod
2929
def get_raw(self) -> bytes: ...
3030
# set_controls and get_controls are not a part of the AbstractCamera ABC,
@@ -34,7 +34,7 @@ class AbstractCamera(ABC):
3434
class Camera(AbstractCamera):
3535
def __init__(
3636
self,
37-
device: Union[str, int] = 0,
37+
device: str | int = 0,
3838
size: IntPoint = (640, 480),
3939
format: str = "RGB",
4040
) -> None: ...
@@ -49,5 +49,5 @@ class Camera(AbstractCamera):
4949
) -> tuple[bool, bool, int]: ...
5050
def get_size(self) -> tuple[int, int]: ...
5151
def query_image(self) -> bool: ...
52-
def get_image(self, surface: Optional[Surface] = None) -> Surface: ...
52+
def get_image(self, surface: Surface | None = None) -> Surface: ...
5353
def get_raw(self) -> bytes: ...

buildconfig/stubs/pygame/color.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from collections.abc import Collection, Iterator
3-
from typing import Any, ClassVar, SupportsIndex, Union, overload
3+
from typing import Any, ClassVar, SupportsIndex, overload
44

55
from pygame.typing import ColorLike
66
from typing_extensions import deprecated # added in 3.13
@@ -47,8 +47,8 @@ class Color(Collection[int]):
4747
def __index__(self) -> int: ...
4848
def __invert__(self) -> Color: ...
4949
def __contains__(self, other: int) -> bool: ... # type: ignore[override]
50-
def __getattribute__(self, name: str) -> Union[Color, tuple[int, ...]]: ...
51-
def __setattr__(self, name: str, value: Union[Color, tuple[int, ...]]) -> None: ...
50+
def __getattribute__(self, name: str) -> Color | tuple[int, ...]: ...
51+
def __setattr__(self, name: str, value: Color | tuple[int, ...]) -> None: ...
5252
@overload
5353
@classmethod
5454
def from_cmy(cls, object: tuple[float, float, float], /) -> Color: ...

buildconfig/stubs/pygame/cursors.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Iterator
2-
from typing import Any, Literal, Union, overload
2+
from typing import Any, Literal, overload
33

44
from pygame.surface import Surface
55
from pygame.typing import FileLike, IntPoint, SequenceLike
@@ -79,11 +79,11 @@ class Cursor:
7979
def __len__(self) -> int: ...
8080
def __copy__(self) -> Cursor: ...
8181
def __hash__(self) -> int: ...
82-
def __getitem__(self, index: int) -> Union[int, IntPoint, Surface]: ...
82+
def __getitem__(self, index: int) -> int | IntPoint | Surface: ...
8383
def copy(self) -> Cursor: ...
8484
type: Literal["system", "color", "bitmap"]
85-
data: Union[
86-
tuple[int],
87-
tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]],
88-
tuple[IntPoint, Surface],
89-
]
85+
data: (
86+
tuple[int]
87+
| tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]]
88+
| tuple[IntPoint, Surface]
89+
)

buildconfig/stubs/pygame/display.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ required).
5252
"""
5353

5454
from collections.abc import Iterable
55-
from typing import Literal, Optional, Union, overload
55+
from typing import Literal, overload
5656

5757
from pygame._sdl2 import Window
5858
from pygame.constants import FULLSCREEN
@@ -285,7 +285,7 @@ def set_mode(
285285
on the major platforms this function was tested with.
286286
"""
287287

288-
def get_surface() -> Optional[Surface]:
288+
def get_surface() -> Surface | None:
289289
"""Get a reference to the currently set display surface.
290290
291291
Return a reference to the currently set display Surface. If no display mode
@@ -304,9 +304,9 @@ def flip() -> None:
304304
@overload
305305
def update() -> None: ...
306306
@overload
307-
def update(rectangle: Optional[RectLike], /) -> None: ...
307+
def update(rectangle: RectLike | None, /) -> None: ...
308308
@overload
309-
def update(rectangles: Iterable[Optional[RectLike]], /) -> None: ...
309+
def update(rectangles: Iterable[RectLike | None], /) -> None: ...
310310
@overload
311311
def update(x: float, y: float, w: float, h: float, /) -> None: ...
312312
@overload
@@ -678,7 +678,7 @@ def set_icon(surface: Surface, /) -> None:
678678
the icon before the display mode is set.
679679
"""
680680

681-
def set_caption(title: str, icontitle: Optional[str] = None, /) -> None:
681+
def set_caption(title: str, icontitle: str | None = None, /) -> None:
682682
"""Set the current window caption.
683683
684684
If the display has a window title, this function will change the name on the
@@ -836,12 +836,12 @@ def get_desktop_refresh_rates() -> list[int]:
836836

837837
def message_box(
838838
title: str,
839-
message: Optional[str] = None,
839+
message: str | None = None,
840840
message_type: Literal["info", "warn", "error"] = "info",
841-
parent_window: Optional[Window] = None,
841+
parent_window: Window | None = None,
842842
buttons: SequenceLike[str] = ("OK",),
843843
return_button: int = 0,
844-
escape_button: Optional[int] = None,
844+
escape_button: int | None = None,
845845
) -> int:
846846
"""Create a native GUI message box.
847847

0 commit comments

Comments
 (0)