Skip to content

Commit 81fc491

Browse files
committed
Use python 3.9isms in typing
1 parent 71ab2e2 commit 81fc491

38 files changed

+234
-287
lines changed

buildconfig/stubs/pygame/_debug.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Tuple, Union, Optional, Callable
1+
from collections.abc import Callable
2+
from typing import Union, Optional
23

3-
ImportResult = Tuple[str, bool, Optional[Callable]]
4+
ImportResult = tuple[str, bool, Optional[Callable]]
45

5-
def str_from_tuple(version_tuple: Union[Tuple[int, int, int], None]) -> str: ...
6+
def str_from_tuple(version_tuple: Union[tuple[int, int, int], None]) -> str: ...
67
def attempt_import(module: str, function_name: str, output_str: str = "") -> ImportResult: ...
78
def print_debug_info(filename: Optional[str] = None) -> None: ...

buildconfig/stubs/pygame/_sdl2/audio.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, List
1+
from collections.abc import Callable
22

33
AUDIO_U8: int
44
AUDIO_S8: int
@@ -20,7 +20,7 @@ AUDIO_ALLOW_FORMAT_CHANGE: int
2020
AUDIO_ALLOW_CHANNELS_CHANGE: int
2121
AUDIO_ALLOW_ANY_CHANGE: int
2222

23-
def get_audio_device_names(iscapture: bool = False) -> List[str]: ...
23+
def get_audio_device_names(iscapture: bool = False) -> list[str]: ...
2424

2525
class AudioDevice:
2626
def __init__(

buildconfig/stubs/pygame/_sdl2/controller_old.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Dict, Mapping, Optional
1+
from collections.abc import Mapping
2+
from typing import Optional
23

34
from pygame.joystick import JoystickType
45

@@ -27,7 +28,7 @@ class Controller:
2728
def as_joystick(self) -> JoystickType: ...
2829
def get_axis(self, axis: int) -> int: ...
2930
def get_button(self, button: int) -> bool: ...
30-
def get_mapping(self) -> Dict[str, str]: ...
31+
def get_mapping(self) -> dict[str, str]: ...
3132
def set_mapping(self, mapping: Mapping[str, str]) -> int: ...
3233
def rumble(
3334
self, low_frequency: float, high_frequency: float, duration: int
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import Dict, Union
1+
from typing import Union
22

33
def get_num_devices() -> int: ...
44
def get_device(index: int) -> int: ...
55
def get_num_fingers(device_id: int) -> int: ...
6-
def get_finger(touchid: int, index: int) -> Dict[str, Union[int, float]]: ...
6+
def get_finger(touchid: int, index: int) -> dict[str, Union[int, float]]: ...

buildconfig/stubs/pygame/_sdl2/video.pyi

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

34
from pygame.color import Color
45
from pygame.rect import Rect
@@ -34,7 +35,7 @@ def messagebox(
3435
info: bool = False,
3536
warn: bool = False,
3637
error: bool = False,
37-
buttons: Tuple[str, ...] = ("OK",),
38+
buttons: tuple[str, ...] = ("OK",),
3839
return_button: int = 0,
3940
escape_button: int = 0,
4041
) -> int: ...
@@ -47,7 +48,7 @@ class Texture:
4748
static: bool = False,
4849
streaming: bool = False,
4950
target: bool = False,
50-
scale_quality: Optional[int] =None
51+
scale_quality: Optional[int] = None,
5152
) -> None: ...
5253
@staticmethod
5354
def from_surface(renderer: Renderer, surface: Surface) -> Texture: ...
@@ -61,7 +62,6 @@ class Texture:
6162
def color(self) -> Color: ...
6263
@color.setter
6364
def color(self, value: ColorLike) -> None: ...
64-
6565
def get_rect(self, **kwargs: Any) -> Rect: ...
6666
def draw(
6767
self,
@@ -176,5 +176,5 @@ class Renderer:
176176
) -> Surface: ...
177177
@staticmethod
178178
def compose_custom_blend_mode(
179-
color_mode: Tuple[int, int, int], alpha_mode: Tuple[int, int, int]
179+
color_mode: tuple[int, int, int], alpha_mode: tuple[int, int, int]
180180
) -> int: ...

buildconfig/stubs/pygame/base.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Tuple, Callable
1+
from collections.abc import Callable
2+
from typing import Any
23

34
__version__: str
45

@@ -8,12 +9,12 @@ class BufferError(Exception): ...
89
# Always defined
910
HAVE_NEWBUF: int = 1
1011

11-
def init() -> Tuple[int, int]: ...
12+
def init() -> tuple[int, int]: ...
1213
def quit() -> None: ...
1314
def get_init() -> bool: ...
1415
def get_error() -> str: ...
1516
def set_error(error_msg: str, /) -> None: ...
16-
def get_sdl_version(linked: bool = True) -> Tuple[int, int, int]: ...
17+
def get_sdl_version(linked: bool = True) -> tuple[int, int, int]: ...
1718
def get_sdl_byteorder() -> int: ...
1819
def register_quit(callable: Callable[[], Any], /) -> None: ...
1920

buildconfig/stubs/pygame/bufferproxy.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Any, Dict, overload
1+
from typing import Any, overload
22

33
class BufferProxy:
44
parent: Any
55
length: int
66
raw: bytes
77
# possibly going to be deprecated/removed soon, in which case these
88
# typestubs must be removed too
9-
__array_interface__: Dict[str, Any]
9+
__array_interface__: dict[str, Any]
1010
__array_struct__: Any
1111
@overload
1212
def __init__(self) -> None: ...

buildconfig/stubs/pygame/camera.pyi

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

44
from pygame.typing import IntPoint
55

66
from pygame.surface import Surface
77

8-
def get_backends() -> List[str]: ...
8+
def get_backends() -> list[str]: ...
99
def init(backend: Optional[str] = None) -> None: ...
1010
def quit() -> None: ...
11-
def list_cameras() -> List[str]: ...
11+
def list_cameras() -> list[str]: ...
1212
def colorspace(
1313
surface: Surface, color: Literal["YUV", "HSV"], dest_surface: Surface = ..., /
1414
) -> Surface: ...
@@ -21,7 +21,7 @@ class AbstractCamera(ABC):
2121
@abstractmethod
2222
def stop(self) -> None: ...
2323
@abstractmethod
24-
def get_size(self) -> Tuple[int, int]: ...
24+
def get_size(self) -> tuple[int, int]: ...
2525
@abstractmethod
2626
def query_image(self) -> bool: ...
2727
@abstractmethod
@@ -41,14 +41,14 @@ class Camera(AbstractCamera):
4141
) -> None: ...
4242
def start(self) -> None: ...
4343
def stop(self) -> None: ...
44-
def get_controls(self) -> Tuple[bool, bool, int]: ...
44+
def get_controls(self) -> tuple[bool, bool, int]: ...
4545
def set_controls(
4646
self,
4747
hflip: bool = ...,
4848
vflip: bool = ...,
4949
brightness: int = ...,
50-
) -> Tuple[bool, bool, int]: ...
51-
def get_size(self) -> Tuple[int, int]: ...
50+
) -> tuple[bool, bool, int]: ...
51+
def get_size(self) -> tuple[int, int]: ...
5252
def query_image(self) -> bool: ...
5353
def get_image(self, surface: Optional[Surface] = None) -> Surface: ...
5454
def get_raw(self) -> bytes: ...

buildconfig/stubs/pygame/color.pyi

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import sys
2-
from typing import Any, Dict, Iterator, SupportsIndex, Tuple, Union, overload
3-
from typing_extensions import deprecated # added in 3.13
1+
from collections.abc import Collection, Iterator
2+
from typing import Any, SupportsIndex, Union, overload
3+
from typing_extensions import deprecated # added in 3.13
44

55
from pygame.typing import ColorLike
66

7-
if sys.version_info >= (3, 9):
8-
from collections.abc import Collection
9-
else:
10-
from typing import Collection
11-
12-
THECOLORS: Dict[str, Tuple[int, int, int, int]]
7+
THECOLORS: dict[str, tuple[int, int, int, int]]
138

149
# Color confirms to the Collection ABC, since it also confirms to
1510
# Sized, Iterable and Container ABCs
@@ -18,11 +13,11 @@ class Color(Collection[int]):
1813
g: int
1914
b: int
2015
a: int
21-
cmy: Tuple[float, float, float]
22-
hsva: Tuple[float, float, float, float]
23-
hsla: Tuple[float, float, float, float]
24-
i1i2i3: Tuple[float, float, float]
25-
normalized: Tuple[float, float, float, float]
16+
cmy: tuple[float, float, float]
17+
hsva: tuple[float, float, float, float]
18+
hsla: tuple[float, float, float, float]
19+
i1i2i3: tuple[float, float, float]
20+
normalized: tuple[float, float, float, float]
2621
__hash__: None # type: ignore
2722
__array_struct__: Any
2823
@overload
@@ -32,7 +27,7 @@ class Color(Collection[int]):
3227
@overload
3328
def __getitem__(self, i: SupportsIndex) -> int: ...
3429
@overload
35-
def __getitem__(self, s: slice) -> Tuple[int, ...]: ...
30+
def __getitem__(self, s: slice) -> tuple[int, ...]: ...
3631
def __setitem__(self, key: int, value: int) -> None: ...
3732
def __iter__(self) -> Iterator[int]: ...
3833
def __add__(self, other: Color) -> Color: ...
@@ -50,35 +45,35 @@ class Color(Collection[int]):
5045
def __setattr__(self, attr: str, value: Union[Color, tuple]) -> None: ...
5146
@overload
5247
@classmethod
53-
def from_cmy(cls, object: Tuple[float, float, float], /) -> Color: ...
48+
def from_cmy(cls, object: tuple[float, float, float], /) -> Color: ...
5449
@overload
5550
@classmethod
5651
def from_cmy(cls, c: float, m: float, y: float, /) -> Color: ...
5752
@overload
5853
@classmethod
59-
def from_hsva(cls, object: Tuple[float, float, float, float], /) -> Color: ...
54+
def from_hsva(cls, object: tuple[float, float, float, float], /) -> Color: ...
6055
@overload
6156
@classmethod
6257
def from_hsva(cls, h: float, s: float, v: float, a: float, /) -> Color: ...
6358
@overload
6459
@classmethod
65-
def from_hsla(cls, object: Tuple[float, float, float, float], /) -> Color: ...
60+
def from_hsla(cls, object: tuple[float, float, float, float], /) -> Color: ...
6661
@overload
6762
@classmethod
6863
def from_hsla(cls, h: float, s: float, l: float, a: float, /) -> Color: ...
6964
@overload
7065
@classmethod
71-
def from_i1i2i3(cls, object: Tuple[float, float, float], /) -> Color: ...
66+
def from_i1i2i3(cls, object: tuple[float, float, float], /) -> Color: ...
7267
@overload
7368
@classmethod
7469
def from_i1i2i3(cls, i1: float, i2: float, i3: float, /) -> Color: ...
7570
@overload
7671
@classmethod
77-
def from_normalized(cls, object: Tuple[float, float, float, float], /) -> Color: ...
72+
def from_normalized(cls, object: tuple[float, float, float, float], /) -> Color: ...
7873
@overload
7974
@classmethod
8075
def from_normalized(cls, r: float, g: float, b: float, a: float, /) -> Color: ...
81-
def normalize(self) -> Tuple[float, float, float, float]: ...
76+
def normalize(self) -> tuple[float, float, float, float]: ...
8277
def correct_gamma(self, gamma: float, /) -> Color: ...
8378
@deprecated("since 2.1.3. Use unpacking instead")
8479
def set_length(self, length: int, /) -> None: ...

buildconfig/stubs/pygame/cursors.pyi

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from typing import Any, Iterator, Literal, Tuple, Union, overload
1+
from collections.abc import Iterator
2+
from typing import Any, Literal, Union, overload
23

34
from pygame.surface import Surface
45

56
from pygame.typing import FileLike, IntPoint, SequenceLike
67

7-
_Small_string = Tuple[
8+
_Small_string = tuple[
89
str, str, str, str, str, str, str, str, str, str, str, str, str, str, str, str
910
]
10-
_Big_string = Tuple[
11+
_Big_string = tuple[
1112
str,
1213
str,
1314
str,
@@ -51,10 +52,10 @@ def compile(
5152
black: str = "X",
5253
white: str = ".",
5354
xor: str = "o",
54-
) -> Tuple[Tuple[int, ...], Tuple[int, ...]]: ...
55+
) -> tuple[tuple[int, ...], tuple[int, ...]]: ...
5556
def load_xbm(
5657
curs: FileLike, mask: FileLike
57-
) -> Tuple[Tuple[int, int], Tuple[int, int], Tuple[int, ...], Tuple[int, ...]]: ...
58+
) -> tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]]: ...
5859

5960
class Cursor:
6061
@overload
@@ -85,7 +86,7 @@ class Cursor:
8586
def copy(self) -> Cursor: ...
8687
type: Literal["system", "color", "bitmap"]
8788
data: Union[
88-
Tuple[int],
89-
Tuple[Tuple[int, int], Tuple[int, int], Tuple[int, ...], Tuple[int, ...]],
90-
Tuple[IntPoint, Surface],
89+
tuple[int],
90+
tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]],
91+
tuple[IntPoint, Surface],
9192
]

buildconfig/stubs/pygame/display.pyi

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Dict, List, Optional, Tuple, Union, overload, Literal, Iterable
1+
from collections.abc import Iterable
2+
from typing import Optional, Union, overload, Literal
23
from typing_extensions import deprecated # added in 3.13
34

45
from pygame.constants import FULLSCREEN
@@ -20,9 +21,9 @@ class _VidInfo:
2021
video_mem: int
2122
bitsize: int
2223
bytesize: int
23-
masks: Tuple[int, int, int, int]
24-
shifts: Tuple[int, int, int, int]
25-
losses: Tuple[int, int, int, int]
24+
masks: tuple[int, int, int, int]
25+
shifts: tuple[int, int, int, int]
26+
losses: tuple[int, int, int, int]
2627
blit_hw: int
2728
blit_hw_CC: int
2829
blit_hw_A: int
@@ -55,12 +56,12 @@ def update(x: int, y: int, w: int, h: int, /) -> None: ...
5556
def update(xy: Point, wh: Point, /) -> None: ...
5657
def get_driver() -> str: ...
5758
def Info() -> _VidInfo: ...
58-
def get_wm_info() -> Dict[str, int]: ...
59+
def get_wm_info() -> dict[str, int]: ...
5960
def list_modes(
6061
depth: int = 0,
6162
flags: int = FULLSCREEN,
6263
display: int = 0,
63-
) -> List[Tuple[int, int]]: ...
64+
) -> list[tuple[int, int]]: ...
6465
def mode_ok(
6566
size: IntPoint,
6667
flags: int = 0,
@@ -80,19 +81,19 @@ def set_gamma_ramp(
8081
) -> int: ...
8182
def set_icon(surface: Surface, /) -> None: ...
8283
def set_caption(title: str, icontitle: Optional[str] = None, /) -> None: ...
83-
def get_caption() -> Tuple[str, str]: ...
84+
def get_caption() -> tuple[str, str]: ...
8485
def set_palette(palette: SequenceLike[ColorLike], /) -> None: ...
8586
def get_num_displays() -> int: ...
86-
def get_window_size() -> Tuple[int, int]: ...
87-
def get_window_position() -> Tuple[int, int]:...
87+
def get_window_size() -> tuple[int, int]: ...
88+
def get_window_position() -> tuple[int, int]:...
8889
def set_window_position(position: Point) -> None:...
8990
def get_allow_screensaver() -> bool: ...
9091
def set_allow_screensaver(value: bool = True) -> None: ...
91-
def get_desktop_sizes() -> List[Tuple[int, int]]: ...
92+
def get_desktop_sizes() -> list[tuple[int, int]]: ...
9293
def is_fullscreen() -> bool: ...
9394
def is_vsync() -> bool: ...
9495
def get_current_refresh_rate() -> int: ...
95-
def get_desktop_refresh_rates() -> List[int]: ...
96+
def get_desktop_refresh_rates() -> list[int]: ...
9697
def message_box(
9798
title: str,
9899
message: Optional[str] = None,

0 commit comments

Comments
 (0)