diff --git a/buildconfig/stubs/pygame/_debug.pyi b/buildconfig/stubs/pygame/_debug.pyi index c325c808f5..a7c8cb1994 100644 --- a/buildconfig/stubs/pygame/_debug.pyi +++ b/buildconfig/stubs/pygame/_debug.pyi @@ -1,7 +1,8 @@ -from typing import Tuple, Union, Optional, Callable +from collections.abc import Callable +from typing import Union, Optional -ImportResult = Tuple[str, bool, Optional[Callable]] +ImportResult = tuple[str, bool, Optional[Callable]] -def str_from_tuple(version_tuple: Union[Tuple[int, int, int], None]) -> str: ... +def str_from_tuple(version_tuple: Union[tuple[int, int, int], None]) -> str: ... def attempt_import(module: str, function_name: str, output_str: str = "") -> ImportResult: ... def print_debug_info(filename: Optional[str] = None) -> None: ... diff --git a/buildconfig/stubs/pygame/_sdl2/audio.pyi b/buildconfig/stubs/pygame/_sdl2/audio.pyi index 332f645ded..fffb94e55f 100644 --- a/buildconfig/stubs/pygame/_sdl2/audio.pyi +++ b/buildconfig/stubs/pygame/_sdl2/audio.pyi @@ -1,4 +1,4 @@ -from typing import Callable, List +from collections.abc import Callable AUDIO_U8: int AUDIO_S8: int @@ -20,7 +20,7 @@ AUDIO_ALLOW_FORMAT_CHANGE: int AUDIO_ALLOW_CHANNELS_CHANGE: int AUDIO_ALLOW_ANY_CHANGE: int -def get_audio_device_names(iscapture: bool = False) -> List[str]: ... +def get_audio_device_names(iscapture: bool = False) -> list[str]: ... class AudioDevice: def __init__( diff --git a/buildconfig/stubs/pygame/_sdl2/controller_old.pyi b/buildconfig/stubs/pygame/_sdl2/controller_old.pyi index 3810fbba0a..e1ae7a54ea 100644 --- a/buildconfig/stubs/pygame/_sdl2/controller_old.pyi +++ b/buildconfig/stubs/pygame/_sdl2/controller_old.pyi @@ -1,4 +1,5 @@ -from typing import Dict, Mapping, Optional +from collections.abc import Mapping +from typing import Optional from pygame.joystick import JoystickType @@ -27,7 +28,7 @@ class Controller: def as_joystick(self) -> JoystickType: ... def get_axis(self, axis: int) -> int: ... def get_button(self, button: int) -> bool: ... - def get_mapping(self) -> Dict[str, str]: ... + def get_mapping(self) -> dict[str, str]: ... def set_mapping(self, mapping: Mapping[str, str]) -> int: ... def rumble( self, low_frequency: float, high_frequency: float, duration: int diff --git a/buildconfig/stubs/pygame/_sdl2/touch.pyi b/buildconfig/stubs/pygame/_sdl2/touch.pyi index 93e2745767..2febfad900 100644 --- a/buildconfig/stubs/pygame/_sdl2/touch.pyi +++ b/buildconfig/stubs/pygame/_sdl2/touch.pyi @@ -1,6 +1,6 @@ -from typing import Dict, Union +from typing import Union def get_num_devices() -> int: ... def get_device(index: int) -> int: ... def get_num_fingers(device_id: int) -> int: ... -def get_finger(touchid: int, index: int) -> Dict[str, Union[int, float]]: ... +def get_finger(touchid: int, index: int) -> dict[str, Union[int, float]]: ... diff --git a/buildconfig/stubs/pygame/_sdl2/video.pyi b/buildconfig/stubs/pygame/_sdl2/video.pyi index 905431df28..8e741e8ab4 100644 --- a/buildconfig/stubs/pygame/_sdl2/video.pyi +++ b/buildconfig/stubs/pygame/_sdl2/video.pyi @@ -1,4 +1,5 @@ -from typing import Any, Generator, Iterable, Optional, Tuple, Union +from collections.abc import Generator, Iterable +from typing import Any, Optional, Union from pygame.color import Color from pygame.rect import Rect @@ -34,7 +35,7 @@ def messagebox( info: bool = False, warn: bool = False, error: bool = False, - buttons: Tuple[str, ...] = ("OK",), + buttons: tuple[str, ...] = ("OK",), return_button: int = 0, escape_button: int = 0, ) -> int: ... @@ -47,7 +48,7 @@ class Texture: static: bool = False, streaming: bool = False, target: bool = False, - scale_quality: Optional[int] =None + scale_quality: Optional[int] = None, ) -> None: ... @staticmethod def from_surface(renderer: Renderer, surface: Surface) -> Texture: ... @@ -61,7 +62,6 @@ class Texture: def color(self) -> Color: ... @color.setter def color(self, value: ColorLike) -> None: ... - def get_rect(self, **kwargs: Any) -> Rect: ... def draw( self, @@ -176,5 +176,5 @@ class Renderer: ) -> Surface: ... @staticmethod def compose_custom_blend_mode( - color_mode: Tuple[int, int, int], alpha_mode: Tuple[int, int, int] + color_mode: tuple[int, int, int], alpha_mode: tuple[int, int, int] ) -> int: ... diff --git a/buildconfig/stubs/pygame/base.pyi b/buildconfig/stubs/pygame/base.pyi index 4aa5d42149..b974235d18 100644 --- a/buildconfig/stubs/pygame/base.pyi +++ b/buildconfig/stubs/pygame/base.pyi @@ -1,4 +1,5 @@ -from typing import Any, Tuple, Callable +from collections.abc import Callable +from typing import Any __version__: str @@ -8,12 +9,12 @@ class BufferError(Exception): ... # Always defined HAVE_NEWBUF: int = 1 -def init() -> Tuple[int, int]: ... +def init() -> tuple[int, int]: ... def quit() -> None: ... def get_init() -> bool: ... def get_error() -> str: ... def set_error(error_msg: str, /) -> None: ... -def get_sdl_version(linked: bool = True) -> Tuple[int, int, int]: ... +def get_sdl_version(linked: bool = True) -> tuple[int, int, int]: ... def get_sdl_byteorder() -> int: ... def register_quit(callable: Callable[[], Any], /) -> None: ... diff --git a/buildconfig/stubs/pygame/bufferproxy.pyi b/buildconfig/stubs/pygame/bufferproxy.pyi index b77eb46c43..6eb21c5f4b 100644 --- a/buildconfig/stubs/pygame/bufferproxy.pyi +++ b/buildconfig/stubs/pygame/bufferproxy.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, overload +from typing import Any, overload class BufferProxy: parent: Any @@ -6,7 +6,7 @@ class BufferProxy: raw: bytes # possibly going to be deprecated/removed soon, in which case these # typestubs must be removed too - __array_interface__: Dict[str, Any] + __array_interface__: dict[str, Any] __array_struct__: Any @overload def __init__(self) -> None: ... diff --git a/buildconfig/stubs/pygame/camera.pyi b/buildconfig/stubs/pygame/camera.pyi index 09dd9f8564..2609bd640f 100644 --- a/buildconfig/stubs/pygame/camera.pyi +++ b/buildconfig/stubs/pygame/camera.pyi @@ -1,14 +1,14 @@ from abc import ABC, abstractmethod -from typing import List, Optional, Tuple, Union, Literal +from typing import Optional, Union, Literal from pygame.typing import IntPoint from pygame.surface import Surface -def get_backends() -> List[str]: ... +def get_backends() -> list[str]: ... def init(backend: Optional[str] = None) -> None: ... def quit() -> None: ... -def list_cameras() -> List[str]: ... +def list_cameras() -> list[str]: ... def colorspace( surface: Surface, color: Literal["YUV", "HSV"], dest_surface: Surface = ..., / ) -> Surface: ... @@ -21,7 +21,7 @@ class AbstractCamera(ABC): @abstractmethod def stop(self) -> None: ... @abstractmethod - def get_size(self) -> Tuple[int, int]: ... + def get_size(self) -> tuple[int, int]: ... @abstractmethod def query_image(self) -> bool: ... @abstractmethod @@ -41,14 +41,14 @@ class Camera(AbstractCamera): ) -> None: ... def start(self) -> None: ... def stop(self) -> None: ... - def get_controls(self) -> Tuple[bool, bool, int]: ... + def get_controls(self) -> tuple[bool, bool, int]: ... def set_controls( self, hflip: bool = ..., vflip: bool = ..., brightness: int = ..., - ) -> Tuple[bool, bool, int]: ... - def get_size(self) -> Tuple[int, int]: ... + ) -> tuple[bool, bool, int]: ... + def get_size(self) -> tuple[int, int]: ... def query_image(self) -> bool: ... def get_image(self, surface: Optional[Surface] = None) -> Surface: ... def get_raw(self) -> bytes: ... diff --git a/buildconfig/stubs/pygame/color.pyi b/buildconfig/stubs/pygame/color.pyi index 635b05d4ea..217e6cab1b 100644 --- a/buildconfig/stubs/pygame/color.pyi +++ b/buildconfig/stubs/pygame/color.pyi @@ -1,15 +1,10 @@ -import sys -from typing import Any, Dict, Iterator, SupportsIndex, Tuple, Union, overload -from typing_extensions import deprecated # added in 3.13 +from collections.abc import Collection, Iterator +from typing import Any, SupportsIndex, Union, overload +from typing_extensions import deprecated # added in 3.13 from pygame.typing import ColorLike -if sys.version_info >= (3, 9): - from collections.abc import Collection -else: - from typing import Collection - -THECOLORS: Dict[str, Tuple[int, int, int, int]] +THECOLORS: dict[str, tuple[int, int, int, int]] # Color confirms to the Collection ABC, since it also confirms to # Sized, Iterable and Container ABCs @@ -18,11 +13,11 @@ class Color(Collection[int]): g: int b: int a: int - cmy: Tuple[float, float, float] - hsva: Tuple[float, float, float, float] - hsla: Tuple[float, float, float, float] - i1i2i3: Tuple[float, float, float] - normalized: Tuple[float, float, float, float] + cmy: tuple[float, float, float] + hsva: tuple[float, float, float, float] + hsla: tuple[float, float, float, float] + i1i2i3: tuple[float, float, float] + normalized: tuple[float, float, float, float] __hash__: None # type: ignore __array_struct__: Any @overload @@ -32,7 +27,7 @@ class Color(Collection[int]): @overload def __getitem__(self, i: SupportsIndex) -> int: ... @overload - def __getitem__(self, s: slice) -> Tuple[int, ...]: ... + def __getitem__(self, s: slice) -> tuple[int, ...]: ... def __setitem__(self, key: int, value: int) -> None: ... def __iter__(self) -> Iterator[int]: ... def __add__(self, other: Color) -> Color: ... @@ -50,35 +45,35 @@ class Color(Collection[int]): def __setattr__(self, attr: str, value: Union[Color, tuple]) -> None: ... @overload @classmethod - def from_cmy(cls, object: Tuple[float, float, float], /) -> Color: ... + def from_cmy(cls, object: tuple[float, float, float], /) -> Color: ... @overload @classmethod def from_cmy(cls, c: float, m: float, y: float, /) -> Color: ... @overload @classmethod - def from_hsva(cls, object: Tuple[float, float, float, float], /) -> Color: ... + def from_hsva(cls, object: tuple[float, float, float, float], /) -> Color: ... @overload @classmethod def from_hsva(cls, h: float, s: float, v: float, a: float, /) -> Color: ... @overload @classmethod - def from_hsla(cls, object: Tuple[float, float, float, float], /) -> Color: ... + def from_hsla(cls, object: tuple[float, float, float, float], /) -> Color: ... @overload @classmethod def from_hsla(cls, h: float, s: float, l: float, a: float, /) -> Color: ... @overload @classmethod - def from_i1i2i3(cls, object: Tuple[float, float, float], /) -> Color: ... + def from_i1i2i3(cls, object: tuple[float, float, float], /) -> Color: ... @overload @classmethod def from_i1i2i3(cls, i1: float, i2: float, i3: float, /) -> Color: ... @overload @classmethod - def from_normalized(cls, object: Tuple[float, float, float, float], /) -> Color: ... + def from_normalized(cls, object: tuple[float, float, float, float], /) -> Color: ... @overload @classmethod def from_normalized(cls, r: float, g: float, b: float, a: float, /) -> Color: ... - def normalize(self) -> Tuple[float, float, float, float]: ... + def normalize(self) -> tuple[float, float, float, float]: ... def correct_gamma(self, gamma: float, /) -> Color: ... @deprecated("since 2.1.3. Use unpacking instead") def set_length(self, length: int, /) -> None: ... diff --git a/buildconfig/stubs/pygame/cursors.pyi b/buildconfig/stubs/pygame/cursors.pyi index d78b797316..ae22d0dcb8 100644 --- a/buildconfig/stubs/pygame/cursors.pyi +++ b/buildconfig/stubs/pygame/cursors.pyi @@ -1,13 +1,14 @@ -from typing import Any, Iterator, Literal, Tuple, Union, overload +from collections.abc import Iterator +from typing import Any, Literal, Union, overload from pygame.surface import Surface from pygame.typing import FileLike, IntPoint, SequenceLike -_Small_string = Tuple[ +_Small_string = tuple[ str, str, str, str, str, str, str, str, str, str, str, str, str, str, str, str ] -_Big_string = Tuple[ +_Big_string = tuple[ str, str, str, @@ -51,10 +52,10 @@ def compile( black: str = "X", white: str = ".", xor: str = "o", -) -> Tuple[Tuple[int, ...], Tuple[int, ...]]: ... +) -> tuple[tuple[int, ...], tuple[int, ...]]: ... def load_xbm( curs: FileLike, mask: FileLike -) -> Tuple[Tuple[int, int], Tuple[int, int], Tuple[int, ...], Tuple[int, ...]]: ... +) -> tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]]: ... class Cursor: @overload @@ -85,7 +86,7 @@ class Cursor: def copy(self) -> Cursor: ... type: Literal["system", "color", "bitmap"] data: Union[ - Tuple[int], - Tuple[Tuple[int, int], Tuple[int, int], Tuple[int, ...], Tuple[int, ...]], - Tuple[IntPoint, Surface], + tuple[int], + tuple[tuple[int, int], tuple[int, int], tuple[int, ...], tuple[int, ...]], + tuple[IntPoint, Surface], ] diff --git a/buildconfig/stubs/pygame/display.pyi b/buildconfig/stubs/pygame/display.pyi index de106bfb19..5124e92b47 100644 --- a/buildconfig/stubs/pygame/display.pyi +++ b/buildconfig/stubs/pygame/display.pyi @@ -1,4 +1,5 @@ -from typing import Dict, List, Optional, Tuple, Union, overload, Literal, Iterable +from collections.abc import Iterable +from typing import Optional, Union, overload, Literal from typing_extensions import deprecated # added in 3.13 from pygame.constants import FULLSCREEN @@ -20,9 +21,9 @@ class _VidInfo: video_mem: int bitsize: int bytesize: int - masks: Tuple[int, int, int, int] - shifts: Tuple[int, int, int, int] - losses: Tuple[int, int, int, int] + masks: tuple[int, int, int, int] + shifts: tuple[int, int, int, int] + losses: tuple[int, int, int, int] blit_hw: int blit_hw_CC: int blit_hw_A: int @@ -55,12 +56,12 @@ def update(x: int, y: int, w: int, h: int, /) -> None: ... def update(xy: Point, wh: Point, /) -> None: ... def get_driver() -> str: ... def Info() -> _VidInfo: ... -def get_wm_info() -> Dict[str, int]: ... +def get_wm_info() -> dict[str, int]: ... def list_modes( depth: int = 0, flags: int = FULLSCREEN, display: int = 0, -) -> List[Tuple[int, int]]: ... +) -> list[tuple[int, int]]: ... def mode_ok( size: IntPoint, flags: int = 0, @@ -80,19 +81,19 @@ def set_gamma_ramp( ) -> int: ... def set_icon(surface: Surface, /) -> None: ... def set_caption(title: str, icontitle: Optional[str] = None, /) -> None: ... -def get_caption() -> Tuple[str, str]: ... +def get_caption() -> tuple[str, str]: ... def set_palette(palette: SequenceLike[ColorLike], /) -> None: ... def get_num_displays() -> int: ... -def get_window_size() -> Tuple[int, int]: ... -def get_window_position() -> Tuple[int, int]:... +def get_window_size() -> tuple[int, int]: ... +def get_window_position() -> tuple[int, int]:... def set_window_position(position: Point) -> None:... def get_allow_screensaver() -> bool: ... def set_allow_screensaver(value: bool = True) -> None: ... -def get_desktop_sizes() -> List[Tuple[int, int]]: ... +def get_desktop_sizes() -> list[tuple[int, int]]: ... def is_fullscreen() -> bool: ... def is_vsync() -> bool: ... def get_current_refresh_rate() -> int: ... -def get_desktop_refresh_rates() -> List[int]: ... +def get_desktop_refresh_rates() -> list[int]: ... def message_box( title: str, message: Optional[str] = None, diff --git a/buildconfig/stubs/pygame/event.pyi b/buildconfig/stubs/pygame/event.pyi index 1987f96de9..c1bb60279c 100644 --- a/buildconfig/stubs/pygame/event.pyi +++ b/buildconfig/stubs/pygame/event.pyi @@ -1,22 +1,17 @@ -from typing import ( - Any, - Dict, - List, - Optional, - Union, - final, -) +from typing import Any, Optional, Union, final from pygame.typing import SequenceLike +_AttrDict = dict[str, Any] + @final class Event: type: int - dict: Dict[str, Any] - __dict__: Dict[str, Any] + dict: _AttrDict + __dict__: _AttrDict __hash__: None # type: ignore def __init__( - self, type: int, dict: Dict[str, Any] = ..., **kwargs: Any + self, type: int, dict: _AttrDict = ..., **kwargs: Any ) -> None: ... def __getattribute__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... @@ -30,7 +25,7 @@ def get( eventtype: Optional[_EventTypes] = None, pump: Any = True, exclude: Optional[_EventTypes] = None, -) -> List[Event]: ... +) -> list[Event]: ... def poll() -> Event: ... def wait(timeout: int = 0) -> Event: ... def peek(eventtype: Optional[_EventTypes] = None, pump: Any = True) -> bool: ... diff --git a/buildconfig/stubs/pygame/font.pyi b/buildconfig/stubs/pygame/font.pyi index ea1074cee7..931d8ceeba 100644 --- a/buildconfig/stubs/pygame/font.pyi +++ b/buildconfig/stubs/pygame/font.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Iterable, List, Literal, Optional, Tuple, Union +from collections.abc import Callable, Hashable, Iterable +from typing import Literal, Optional, Union from pygame.surface import Surface @@ -11,9 +12,9 @@ UCS4: Literal[1] def init() -> None: ... def quit() -> None: ... def get_init() -> bool: ... -def get_sdl_ttf_version(linked: bool = True) -> Tuple[int, int, int]: ... +def get_sdl_ttf_version(linked: bool = True) -> tuple[int, int, int]: ... def get_default_font() -> str: ... -def get_fonts() -> List[str]: ... +def get_fonts() -> list[str]: ... def match_font( name: Union[str, bytes, Iterable[Union[str, bytes]]], bold: Hashable = False, @@ -65,7 +66,7 @@ class Font: bgcolor: Optional[ColorLike] = None, wraplength: int = 0, ) -> Surface: ... - def size(self, text: Union[str, bytes], /) -> Tuple[int, int]: ... + def size(self, text: Union[str, bytes], /) -> tuple[int, int]: ... def set_underline(self, value: bool, /) -> None: ... def get_underline(self) -> bool: ... def set_strikethrough(self, value: bool, /) -> None: ... @@ -75,7 +76,7 @@ class Font: def set_italic(self, value: bool, /) -> None: ... def metrics( self, text: Union[str, bytes], / - ) -> List[Tuple[int, int, int, int, int]]: ... + ) -> list[tuple[int, int, int, int, int]]: ... def get_italic(self) -> bool: ... def get_linesize(self) -> int: ... def get_height(self) -> int: ... diff --git a/buildconfig/stubs/pygame/freetype.pyi b/buildconfig/stubs/pygame/freetype.pyi index 8ce24499b8..1953766aef 100644 --- a/buildconfig/stubs/pygame/freetype.pyi +++ b/buildconfig/stubs/pygame/freetype.pyi @@ -1,4 +1,5 @@ -from typing import Any, Callable, Iterable, List, Optional, Tuple, Union +from collections.abc import Callable, Iterable +from typing import Any, Optional, Union from typing_extensions import deprecated # added in 3.13 from pygame.color import Color @@ -8,7 +9,7 @@ from pygame.surface import Surface from pygame.typing import ColorLike, FileLike, RectLike def get_error() -> str: ... -def get_version(linked: bool = True) -> Tuple[int, int, int]: ... +def get_version(linked: bool = True) -> tuple[int, int, int]: ... def init(cache_size: int = 64, resolution: int = 72) -> None: ... def quit() -> None: ... def get_init() -> bool: ... @@ -25,7 +26,7 @@ def SysFont( constructor: Optional[Callable[[Optional[str], int, bool, bool], Font]] = None, ) -> Font: ... def get_default_font() -> str: ... -def get_fonts() -> List[str]: ... +def get_fonts() -> list[str]: ... def match_font( name: Union[str, bytes, Iterable[Union[str, bytes]]], bold: Any = False, @@ -41,9 +42,9 @@ STYLE_DEFAULT: int class Font: @property - def size(self) -> Union[float, Tuple[float, float]]: ... + def size(self) -> Union[float, tuple[float, float]]: ... @size.setter - def size(self, value: Union[float, Tuple[float, float]]) -> None: ... + def size(self, value: Union[float, tuple[float, float]]) -> None: ... @property def style(self) -> int: ... @style.setter @@ -149,12 +150,12 @@ class Font: ) -> Rect: ... def get_metrics( self, text: str, size: float = 0 - ) -> List[Tuple[int, int, int, int, float, float]]: ... + ) -> list[tuple[int, int, int, int, float, float]]: ... def get_sized_ascender(self, size: float, /) -> int: ... def get_sized_descender(self, size: float, /) -> int: ... def get_sized_height(self, size: float, /) -> int: ... def get_sized_glyph_height(self, size: float, /) -> int: ... - def get_sizes(self) -> List[Tuple[int, int, int, float, float]]: ... + def get_sizes(self) -> list[tuple[int, int, int, float, float]]: ... def render( self, text: str, @@ -163,7 +164,7 @@ class Font: style: int = STYLE_DEFAULT, rotation: int = 0, size: float = 0, - ) -> Tuple[Surface, Rect]: ... + ) -> tuple[Surface, Rect]: ... def render_to( self, surf: Surface, @@ -182,7 +183,7 @@ class Font: rotation: int = 0, size: float = 0, invert: bool = False, - ) -> Tuple[bytes, Tuple[int, int]]: ... + ) -> tuple[bytes, tuple[int, int]]: ... def render_raw_to( self, array: Any, diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 4814310b6e..bd39853e88 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -1,19 +1,12 @@ -from typing import ( - overload, - Union, - Callable, - Protocol, - Tuple, - Sequence, - List, -) +from collections.abc import Callable +from typing import overload, Union, Protocol from pygame import Rect, FRect from pygame.typing import Point, RectLike, SequenceLike from .rect import Rect, FRect from .math import Vector2 -_CanBeCircle = Union[Circle, Tuple[Point, float], SequenceLike[float]] +_CanBeCircle = Union[Circle, tuple[Point, float], SequenceLike[float]] class _HasCirclettribute(Protocol): # An object that has a circle attribute that is either a circle, or a function @@ -62,7 +55,7 @@ class Circle: @circumference.setter def circumference(self, value: float) -> None: ... @property - def center(self) -> Tuple[float, float]: ... + def center(self) -> tuple[float, float]: ... @center.setter def center(self, value: Point) -> None: ... @property @@ -112,9 +105,11 @@ class Circle: @overload def colliderect(self, topleft: Point, size: Point, /) -> bool: ... def collideswith(self, other: _CanBeCollided, /) -> bool: ... - def collidelist(self, colliders: Sequence[_CanBeCollided], /) -> int: ... - def collidelistall(self, colliders: Sequence[_CanBeCollided], /) -> List[int]: ... - def intersect(self, other: _CanBeIntersected, /) -> List[Tuple[float, float]]: ... + def collidelist(self, colliders: SequenceLike[_CanBeCollided], /) -> int: ... + def collidelistall( + self, colliders: SequenceLike[_CanBeCollided], / + ) -> tuple[int]: ... + def intersect(self, other: _CanBeIntersected, /) -> list[tuple[float, float]]: ... def contains(self, shape: _CanBeCollided) -> bool: ... @overload def update(self, circle: _CircleValue, /) -> None: ... diff --git a/buildconfig/stubs/pygame/image.pyi b/buildconfig/stubs/pygame/image.pyi index a85af02e09..7a11a55cc5 100644 --- a/buildconfig/stubs/pygame/image.pyi +++ b/buildconfig/stubs/pygame/image.pyi @@ -1,4 +1,4 @@ -from typing import Literal, Optional, Tuple, Union +from typing import Literal, Optional, Union from typing_extensions import deprecated # added in 3.13 from pygame.bufferproxy import BufferProxy @@ -16,7 +16,7 @@ _from_bytes_format = Literal["P", "RGB", "RGBX", "RGBA", "ARGB", "BGRA", "ABGR"] def load(file: FileLike, namehint: str = "") -> Surface: ... def load_sized_svg(file: FileLike, size: Point) -> Surface: ... def save(surface: Surface, file: FileLike, namehint: str = "") -> None: ... -def get_sdl_image_version(linked: bool = True) -> Optional[Tuple[int, int, int]]: ... +def get_sdl_image_version(linked: bool = True) -> Optional[tuple[int, int, int]]: ... def get_extended() -> bool: ... @deprecated("since 2.3.0. Use `pygame.image.tobytes` instead") def tostring( diff --git a/buildconfig/stubs/pygame/joystick.pyi b/buildconfig/stubs/pygame/joystick.pyi index 2936e5a2b3..517829bf2c 100644 --- a/buildconfig/stubs/pygame/joystick.pyi +++ b/buildconfig/stubs/pygame/joystick.pyi @@ -1,5 +1,5 @@ -from typing import Tuple, final -from typing_extensions import deprecated # added in 3.13 +from typing import final +from typing_extensions import deprecated # added in 3.13 def init() -> None: ... def quit() -> None: ... @@ -21,11 +21,11 @@ class JoystickType: def get_numaxes(self) -> int: ... def get_axis(self, axis_number: int, /) -> float: ... def get_numballs(self) -> int: ... - def get_ball(self, ball_number: int, /) -> Tuple[float, float]: ... + def get_ball(self, ball_number: int, /) -> tuple[float, float]: ... def get_numbuttons(self) -> int: ... def get_button(self, button: int, /) -> bool: ... def get_numhats(self) -> int: ... - def get_hat(self, hat_number: int, /) -> Tuple[float, float]: ... + def get_hat(self, hat_number: int, /) -> tuple[float, float]: ... def rumble( self, low_frequency: float, high_frequency: float, duration: int ) -> bool: ... diff --git a/buildconfig/stubs/pygame/key.pyi b/buildconfig/stubs/pygame/key.pyi index 09aa380b35..24a61739bb 100644 --- a/buildconfig/stubs/pygame/key.pyi +++ b/buildconfig/stubs/pygame/key.pyi @@ -1,8 +1,6 @@ -from typing import Tuple - from pygame.typing import RectLike -class ScancodeWrapper(Tuple[bool, ...]): ... +class ScancodeWrapper(tuple[bool, ...]): ... def get_focused() -> bool: ... def get_pressed() -> ScancodeWrapper: ... @@ -11,7 +9,7 @@ def get_just_released() -> ScancodeWrapper: ... def get_mods() -> int: ... def set_mods(mods: int, /) -> None: ... def set_repeat(delay: int = 0, interval: int = 0, /) -> None: ... -def get_repeat() -> Tuple[int, int]: ... +def get_repeat() -> tuple[int, int]: ... def name(key: int, use_compat: bool = True) -> str: ... def key_code(name: str) -> int: ... def start_text_input() -> None: ... diff --git a/buildconfig/stubs/pygame/mask.pyi b/buildconfig/stubs/pygame/mask.pyi index a866c469d4..18d6e4e69d 100644 --- a/buildconfig/stubs/pygame/mask.pyi +++ b/buildconfig/stubs/pygame/mask.pyi @@ -1,4 +1,4 @@ -from typing import Any, List, Optional, Tuple, Union +from typing import Any, Optional, Union from pygame.rect import Rect from pygame.surface import Surface @@ -18,11 +18,11 @@ class Mask: def __init__(self, size: Point, fill: bool = False) -> None: ... def __copy__(self) -> Mask: ... def copy(self) -> Mask: ... - def get_size(self) -> Tuple[int, int]: ... + def get_size(self) -> tuple[int, int]: ... def get_rect(self, **kwargs: Any) -> Rect: ... # Dict type needs to be completed def get_at(self, pos: Point) -> int: ... def set_at(self, pos: Point, value: int = 1) -> None: ... - def overlap(self, other: Mask, offset: Point) -> Optional[Tuple[int, int]]: ... + def overlap(self, other: Mask, offset: Point) -> Optional[tuple[int, int]]: ... def overlap_area(self, other: Mask, offset: Point) -> int: ... def overlap_mask(self, other: Mask, offset: Point) -> Mask: ... def fill(self) -> None: ... @@ -32,9 +32,9 @@ class Mask: def draw(self, other: Mask, offset: Point) -> None: ... def erase(self, other: Mask, offset: Point) -> None: ... def count(self) -> int: ... - def centroid(self) -> Tuple[int, int]: ... + def centroid(self) -> tuple[int, int]: ... def angle(self) -> float: ... - def outline(self, every: int = 1) -> List[Tuple[int, int]]: ... + def outline(self, every: int = 1) -> list[tuple[int, int]]: ... def convolve( self, other: Mask, @@ -42,8 +42,8 @@ class Mask: offset: Point = (0, 0), ) -> Mask: ... def connected_component(self, pos: Point = ...) -> Mask: ... - def connected_components(self, minimum: int = 0) -> List[Mask]: ... - def get_bounding_rects(self) -> List[Rect]: ... + def connected_components(self, minimum: int = 0) -> list[Mask]: ... + def get_bounding_rects(self) -> list[Rect]: ... def to_surface( self, surface: Optional[Surface] = None, diff --git a/buildconfig/stubs/pygame/math.pyi b/buildconfig/stubs/pygame/math.pyi index 4526960b5a..5387d31a72 100644 --- a/buildconfig/stubs/pygame/math.pyi +++ b/buildconfig/stubs/pygame/math.pyi @@ -1,13 +1,9 @@ -import sys +from collections.abc import Collection, Iterator from typing import ( Any, Generic, - Iterator, - List, Literal, SupportsIndex, - Tuple, - Type, TypeVar, Union, final, @@ -16,11 +12,6 @@ from typing import ( ) from typing_extensions import deprecated # added in 3.13 -if sys.version_info >= (3, 9): - from collections.abc import Collection -else: - from typing import Collection - from pygame.typing import SequenceLike def clamp(value: float, min: float, max: float, /) -> float: ... @@ -41,7 +32,7 @@ class _GenericVector(Collection[float]): @overload def __getitem__(self, i: SupportsIndex) -> float: ... @overload - def __getitem__(self, s: slice) -> List[float]: ... + def __getitem__(self, s: slice) -> list[float]: ... def __iter__(self) -> VectorIterator: ... def __add__(self: _TVec, other: Union[SequenceLike[float], _TVec]) -> _TVec: ... def __radd__(self: _TVec, other: Union[SequenceLike[float], _TVec]) -> _TVec: ... @@ -228,7 +219,7 @@ class Vector2(_GenericVector): ) -> None: ... @overload def __init__(self, x: float, y: float) -> None: ... - def __reduce__(self: _TVec) -> Tuple[Type[_TVec], Tuple[float, float]]: ... + def __reduce__(self: _TVec) -> tuple[type[_TVec], tuple[float, float]]: ... def rotate(self: _TVec, angle: float, /) -> _TVec: ... def rotate_rad(self: _TVec, angle: float, /) -> _TVec: ... def rotate_ip(self, angle: float, /) -> None: ... @@ -236,7 +227,7 @@ class Vector2(_GenericVector): @deprecated("since 2.1.1. Use `pygame.Vector2.rotate_rad_ip` instead") def rotate_ip_rad(self, angle: float, /) -> None: ... def cross(self: _TVec, other: Union[SequenceLike[float], _TVec], /) -> float: ... - def as_polar(self) -> Tuple[float, float]: ... + def as_polar(self) -> tuple[float, float]: ... def from_polar(self, polar_value: SequenceLike[float], /) -> None: ... @overload def update( @@ -293,7 +284,7 @@ class Vector3(_GenericVector): ) -> None: ... @overload def __init__(self, x: float, y: float, z: float) -> None: ... - def __reduce__(self: _TVec) -> Tuple[Type[_TVec], Tuple[float, float, float]]: ... + def __reduce__(self: _TVec) -> tuple[type[_TVec], tuple[float, float, float]]: ... def cross(self: _TVec, other: Union[SequenceLike[float], _TVec], /) -> _TVec: ... def rotate( self: _TVec, angle: float, axis: Union[SequenceLike[float], _TVec], / @@ -329,8 +320,8 @@ class Vector3(_GenericVector): def rotate_z_rad_ip(self, angle: float, /) -> None: ... @deprecated("since 2.1.1. Use `pygame.Vector3.rotate_z_rad_ip` instead") def rotate_z_ip_rad(self, angle: float, /) -> None: ... - def as_spherical(self) -> Tuple[float, float, float]: ... - def from_spherical(self, spherical: Tuple[float, float, float], /) -> None: ... + def as_spherical(self) -> tuple[float, float, float]: ... + def from_spherical(self, spherical: tuple[float, float, float], /) -> None: ... @overload def update( self: _TVec, diff --git a/buildconfig/stubs/pygame/midi.pyi b/buildconfig/stubs/pygame/midi.pyi index 22fc749f80..4cce264e26 100644 --- a/buildconfig/stubs/pygame/midi.pyi +++ b/buildconfig/stubs/pygame/midi.pyi @@ -1,4 +1,4 @@ -from typing import List, Tuple, Union +from typing import Union from pygame.event import Event from pygame.typing import SequenceLike @@ -15,10 +15,10 @@ def get_init() -> bool: ... def get_count() -> int: ... def get_default_input_id() -> int: ... def get_default_output_id() -> int: ... -def get_device_info(an_id: int) -> Tuple[str, str, int, int, int]: ... +def get_device_info(an_id: int) -> tuple[str, str, int, int, int]: ... def midis2events( midis: SequenceLike[SequenceLike[Union[SequenceLike[int], int]]], device_id: int -) -> List[Event]: ... +) -> list[Event]: ... def time() -> int: ... def frequency_to_midi(frequency: float) -> int: ... def midi_to_frequency(midi_note: int) -> float: ... @@ -29,7 +29,7 @@ class Input: def __init__(self, device_id: int, buffer_size: int = 4096) -> None: ... def close(self) -> None: ... def poll(self) -> bool: ... - def read(self, num_events: int) -> List[List[Union[List[int], int]]]: ... + def read(self, num_events: int) -> list[list[Union[list[int], int]]]: ... class Output: device_id: int @@ -45,6 +45,6 @@ class Output: def note_on(self, note: int, velocity: int, channel: int = 0) -> None: ... def set_instrument(self, instrument_id: int, channel: int = 0) -> None: ... def pitch_bend(self, value: int = 0, channel: int = 0) -> None: ... - def write(self, data: List[List[Union[List[int], int]]]) -> None: ... + def write(self, data: list[list[Union[list[int], int]]]) -> None: ... def write_short(self, status: int, data1: int = 0, data2: int = 0) -> None: ... - def write_sys_ex(self, when: int, msg: Union[List[int], str]) -> None: ... + def write_sys_ex(self, when: int, msg: Union[list[int], str]) -> None: ... diff --git a/buildconfig/stubs/pygame/mixer.pyi b/buildconfig/stubs/pygame/mixer.pyi index 84646b419b..205679768c 100644 --- a/buildconfig/stubs/pygame/mixer.pyi +++ b/buildconfig/stubs/pygame/mixer.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, Optional, Tuple, Union, overload +from typing import Any, Optional, Union, overload import numpy @@ -27,7 +27,7 @@ def pre_init( allowedchanges: int = 5, ) -> None: ... def quit() -> None: ... -def get_init() -> Tuple[int, int, int]: ... +def get_init() -> tuple[int, int, int]: ... def get_driver() -> str: ... def stop() -> None: ... def pause() -> None: ... @@ -40,7 +40,7 @@ def find_channel(force: bool = False) -> Channel: ... def set_soundfont(paths: Optional[str] = None, /) -> None: ... def get_soundfont() -> Optional[str]: ... def get_busy() -> bool: ... -def get_sdl_mixer_version(linked: bool = True) -> Tuple[int, int, int]: ... +def get_sdl_mixer_version(linked: bool = True) -> tuple[int, int, int]: ... class Sound: @overload @@ -61,7 +61,7 @@ class Sound: ) -> Channel: ... # possibly going to be deprecated/removed soon, in which case these # typestubs must be removed too - __array_interface__: Dict[str, Any] + __array_interface__: dict[str, Any] __array_struct__: Any def stop(self) -> None: ... def fadeout(self, time: int, /) -> None: ... diff --git a/buildconfig/stubs/pygame/mixer_music.pyi b/buildconfig/stubs/pygame/mixer_music.pyi index 40cf46e2a9..a7000be125 100644 --- a/buildconfig/stubs/pygame/mixer_music.pyi +++ b/buildconfig/stubs/pygame/mixer_music.pyi @@ -1,4 +1,4 @@ -from typing import Optional, Dict +from typing import Optional from pygame.typing import FileLike @@ -18,4 +18,4 @@ def get_pos() -> int: ... def queue(filename: FileLike, namehint: str = "", loops: int = 0) -> None: ... def set_endevent(event_type: int, /) -> None: ... def get_endevent() -> int: ... -def get_metadata(filename: Optional[FileLike] = None, namehint: str = "") -> Dict[str, str]: ... +def get_metadata(filename: Optional[FileLike] = None, namehint: str = "") -> dict[str, str]: ... diff --git a/buildconfig/stubs/pygame/mouse.pyi b/buildconfig/stubs/pygame/mouse.pyi index d10fc742de..805862812d 100644 --- a/buildconfig/stubs/pygame/mouse.pyi +++ b/buildconfig/stubs/pygame/mouse.pyi @@ -1,4 +1,4 @@ -from typing import Literal, Tuple, overload +from typing import Literal, overload from typing_extensions import deprecated # added in 3.13 from pygame.cursors import Cursor @@ -9,15 +9,15 @@ from pygame.typing import Point, SequenceLike, IntPoint @overload def get_pressed( num_buttons: Literal[3] = 3, - desktop: bool = False) -> Tuple[bool, bool, bool]: ... + desktop: bool = False) -> tuple[bool, bool, bool]: ... @overload def get_pressed( num_buttons: Literal[5], - desktop: bool = False) -> Tuple[bool, bool, bool, bool, bool]: ... -def get_just_pressed() -> Tuple[bool, bool, bool, bool, bool]: ... -def get_just_released() -> Tuple[bool, bool, bool, bool, bool]: ... -def get_pos(desktop: bool = False) -> Tuple[int, int]: ... -def get_rel() -> Tuple[int, int]: ... + desktop: bool = False) -> tuple[bool, bool, bool, bool, bool]: ... +def get_just_pressed() -> tuple[bool, bool, bool, bool, bool]: ... +def get_just_released() -> tuple[bool, bool, bool, bool, bool]: ... +def get_pos(desktop: bool = False) -> tuple[int, int]: ... +def get_rel() -> tuple[int, int]: ... @overload def set_pos(pos: Point, /) -> None: ... @overload diff --git a/buildconfig/stubs/pygame/pixelarray.pyi b/buildconfig/stubs/pygame/pixelarray.pyi index a10bb66e42..fe7a176fe0 100644 --- a/buildconfig/stubs/pygame/pixelarray.pyi +++ b/buildconfig/stubs/pygame/pixelarray.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, Tuple, Union, overload +from typing import Any, Union, overload from pygame.surface import Surface @@ -8,11 +8,11 @@ class PixelArray: surface: Surface itemsize: int ndim: int - shape: Tuple[int, ...] - strides: Tuple[int, ...] + shape: tuple[int, ...] + strides: tuple[int, ...] # possibly going to be deprecated/removed soon, in which case these # typestubs must be removed too - __array_interface__: Dict[str, Any] + __array_interface__: dict[str, Any] __array_struct__: Any def __init__(self, surface: Surface) -> None: ... def __enter__(self) -> PixelArray: ... @@ -27,7 +27,7 @@ class PixelArray: def __getitem__(self, index_range: slice) -> Union[PixelArray, None]: ... # only valid for a 2D PixelArray @overload - def __getitem__(self, indices: Tuple[int, int]) -> int: ... + def __getitem__(self, indices: tuple[int, int]) -> int: ... # returns self @overload def __getitem__(self, ell: ellipsis) -> PixelArray: ... diff --git a/buildconfig/stubs/pygame/rect.pyi b/buildconfig/stubs/pygame/rect.pyi index d18ea3cdf4..72bf30b73f 100644 --- a/buildconfig/stubs/pygame/rect.pyi +++ b/buildconfig/stubs/pygame/rect.pyi @@ -1,14 +1,11 @@ import sys +from collections.abc import Callable, Collection, Iterator from typing import ( - Dict, - List, Literal, SupportsIndex, - Tuple, TypeVar, Union, overload, - Callable, Optional, ) @@ -19,11 +16,6 @@ if sys.version_info >= (3, 11): else: from typing_extensions import Self -if sys.version_info >= (3, 9): - from collections.abc import Collection, Iterator -else: - from typing import Collection, Iterator - _N = TypeVar("_N", int, float) _K = TypeVar("_K") _V = TypeVar("_V") @@ -57,39 +49,39 @@ class _GenericRect(Collection[_N]): @right.setter def right(self, value: float) -> None: ... @property - def topleft(self) -> Tuple[_N, _N]: ... + def topleft(self) -> tuple[_N, _N]: ... @topleft.setter def topleft(self, value: Point) -> None: ... @property - def bottomleft(self) -> Tuple[_N, _N]: ... + def bottomleft(self) -> tuple[_N, _N]: ... @bottomleft.setter def bottomleft(self, value: Point) -> None: ... @property - def topright(self) -> Tuple[_N, _N]: ... + def topright(self) -> tuple[_N, _N]: ... @topright.setter def topright(self, value: Point) -> None: ... @property - def bottomright(self) -> Tuple[_N, _N]: ... + def bottomright(self) -> tuple[_N, _N]: ... @bottomright.setter def bottomright(self, value: Point) -> None: ... @property - def midtop(self) -> Tuple[_N, _N]: ... + def midtop(self) -> tuple[_N, _N]: ... @midtop.setter def midtop(self, value: Point) -> None: ... @property - def midleft(self) -> Tuple[_N, _N]: ... + def midleft(self) -> tuple[_N, _N]: ... @midleft.setter def midleft(self, value: Point) -> None: ... @property - def midbottom(self) -> Tuple[_N, _N]: ... + def midbottom(self) -> tuple[_N, _N]: ... @midbottom.setter def midbottom(self, value: Point) -> None: ... @property - def midright(self) -> Tuple[_N, _N]: ... + def midright(self) -> tuple[_N, _N]: ... @midright.setter def midright(self, value: Point) -> None: ... @property - def center(self) -> Tuple[_N, _N]: ... + def center(self) -> tuple[_N, _N]: ... @center.setter def center(self, value: Point) -> None: ... @property @@ -101,7 +93,7 @@ class _GenericRect(Collection[_N]): @centery.setter def centery(self, value: float) -> None: ... @property - def size(self) -> Tuple[_N, _N]: ... + def size(self) -> tuple[_N, _N]: ... @size.setter def size(self, value: Point) -> None: ... @property @@ -137,7 +129,7 @@ class _GenericRect(Collection[_N]): @overload def __getitem__(self, i: SupportsIndex) -> _N: ... @overload - def __getitem__(self, s: slice) -> List[_N]: ... + def __getitem__(self, s: slice) -> list[_N]: ... @overload def __setitem__(self, key: int, value: float) -> None: ... @overload @@ -198,15 +190,15 @@ class _GenericRect(Collection[_N]): @overload def clipline( self, x1: float, x2: float, x3: float, x4: float, / - ) -> Union[Tuple[Tuple[_N, _N], Tuple[_N, _N]], Tuple[()]]: ... + ) -> Union[tuple[tuple[_N, _N], tuple[_N, _N]], tuple[()]]: ... @overload def clipline( self, first_point: Point, second_point: Point, / - ) -> Union[Tuple[Tuple[_N, _N], Tuple[_N, _N]], Tuple[()]]: ... + ) -> Union[tuple[tuple[_N, _N], tuple[_N, _N]], tuple[()]]: ... @overload def clipline( self, rect_arg: RectLike, / - ) -> Union[Tuple[Tuple[_N, _N], Tuple[_N, _N]], Tuple[()]]: ... + ) -> Union[tuple[tuple[_N, _N], tuple[_N, _N]], tuple[()]]: ... @overload def union(self, rect: RectLike, /) -> Self: ... @overload @@ -252,29 +244,29 @@ class _GenericRect(Collection[_N]): self, left: float, top: float, width: float, height: float, / ) -> bool: ... def collidelist(self, rect_list: SequenceLike[_RectTypeCompatible_co], /) -> int: ... - def collidelistall(self, rect_list: SequenceLike[_RectTypeCompatible_co], /) -> List[int]: ... + def collidelistall(self, rect_list: SequenceLike[_RectTypeCompatible_co], /) -> list[int]: ... def collideobjectsall( self, objects: SequenceLike[_T], key: Optional[Callable[[_T], RectLike]] = None - ) -> List[_T]: ... + ) -> list[_T]: ... def collideobjects( self, objects: SequenceLike[_T], key: Optional[Callable[[_T], RectLike]] = None ) -> Optional[_T]: ... @overload def collidedict( - self, rect_dict: Dict[_RectTypeCompatible_co, _V], values: Literal[False] = False - ) -> Optional[Tuple[_RectTypeCompatible_co, _V]]: ... + self, rect_dict: dict[_RectTypeCompatible_co, _V], values: Literal[False] = False + ) -> Optional[tuple[_RectTypeCompatible_co, _V]]: ... @overload def collidedict( - self, rect_dict: Dict[_K, _RectTypeCompatible_co], values: Literal[True] - ) -> Optional[Tuple[_K, _RectTypeCompatible_co]]: ... + self, rect_dict: dict[_K, _RectTypeCompatible_co], values: Literal[True] + ) -> Optional[tuple[_K, _RectTypeCompatible_co]]: ... @overload def collidedictall( - self, rect_dict: Dict[_RectTypeCompatible_co, _V], values: Literal[False] = False - ) -> List[Tuple[_RectTypeCompatible_co, _V]]: ... + self, rect_dict: dict[_RectTypeCompatible_co, _V], values: Literal[False] = False + ) -> list[tuple[_RectTypeCompatible_co, _V]]: ... @overload def collidedictall( - self, rect_dict: Dict[_K, _RectTypeCompatible_co], values: Literal[True] - ) -> List[Tuple[_K, _RectTypeCompatible_co]]: ... + self, rect_dict: dict[_K, _RectTypeCompatible_co], values: Literal[True] + ) -> list[tuple[_K, _RectTypeCompatible_co]]: ... # Rect confirms to the Collection ABC, since it also confirms to # Sized, Iterable and Container ABCs diff --git a/buildconfig/stubs/pygame/rwobject.pyi b/buildconfig/stubs/pygame/rwobject.pyi index d14c62a804..11eb417a5b 100644 --- a/buildconfig/stubs/pygame/rwobject.pyi +++ b/buildconfig/stubs/pygame/rwobject.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional, overload, Type +from typing import Any, Optional, overload from pygame.typing import _PathLike @@ -6,13 +6,13 @@ def encode_string( obj: Optional[_PathLike], encoding: Optional[str] = "unicode_escape", errors: Optional[str] = "backslashreplace", - etype: Optional[Type[Exception]] = UnicodeEncodeError, + etype: Optional[type[Exception]] = UnicodeEncodeError, ) -> bytes: ... @overload def encode_file_path( - obj: Optional[_PathLike], etype: Optional[Type[Exception]] = UnicodeEncodeError + obj: Optional[_PathLike], etype: Optional[type[Exception]] = UnicodeEncodeError ) -> bytes: ... @overload def encode_file_path( - obj: Any, etype: Optional[Type[Exception]] = UnicodeEncodeError + obj: Any, etype: Optional[type[Exception]] = UnicodeEncodeError ) -> bytes: ... diff --git a/buildconfig/stubs/pygame/scrap.pyi b/buildconfig/stubs/pygame/scrap.pyi index edb98e8801..54e8044bd2 100644 --- a/buildconfig/stubs/pygame/scrap.pyi +++ b/buildconfig/stubs/pygame/scrap.pyi @@ -1,4 +1,4 @@ -from typing import List, Optional +from typing import Optional from typing_extensions import deprecated # added in 3.13 from collections.abc import ByteString @@ -9,7 +9,7 @@ def get_init() -> bool: ... @deprecated("since 2.2.0. Use the new API instead: `pygame.scrap.get_text`") def get(data_type: str, /) -> Optional[bytes]: ... @deprecated("since 2.2.0. Use the new API instead, which only supports strings") -def get_types() -> List[str]: ... +def get_types() -> list[str]: ... @deprecated("since 2.2.0. Use the new API instead: `pygame.scrap.put_text`") def put(data_type: str, data: ByteString, /) -> None: ... @deprecated("since 2.2.0. Use the new API instead: `pygame.scrap.has_text`") diff --git a/buildconfig/stubs/pygame/sndarray.pyi b/buildconfig/stubs/pygame/sndarray.pyi index bf03698feb..0f0342a92a 100644 --- a/buildconfig/stubs/pygame/sndarray.pyi +++ b/buildconfig/stubs/pygame/sndarray.pyi @@ -1,4 +1,3 @@ -from typing import Tuple from typing_extensions import deprecated # added in 3.13 import numpy @@ -13,4 +12,4 @@ def use_arraytype(arraytype: str) -> Sound: ... @deprecated("Only numpy is supported") def get_arraytype() -> str: ... @deprecated("Only numpy is supported") -def get_arraytypes() -> Tuple[str]: ... +def get_arraytypes() -> tuple[str]: ... diff --git a/buildconfig/stubs/pygame/sprite.pyi b/buildconfig/stubs/pygame/sprite.pyi index 8220c36ba9..e29ebfc183 100644 --- a/buildconfig/stubs/pygame/sprite.pyi +++ b/buildconfig/stubs/pygame/sprite.pyi @@ -1,15 +1,10 @@ +from collections.abc import Callable, Iterable, Iterator from typing import ( Any, - Callable, - Dict, Generic, - Iterable, - Iterator, - List, Optional, Protocol, SupportsFloat, - Tuple, TypeVar, Union, ) @@ -46,7 +41,7 @@ class _SupportsSprite(Protocol): def remove(self, *groups: _Group) -> None: ... def kill(self) -> None: ... def alive(self) -> bool: ... - def groups(self) -> List[_Group]: ... + def groups(self) -> list[_Group]: ... # also a protocol class _SupportsDirtySprite(_SupportsSprite, Protocol): @@ -80,7 +75,7 @@ class Sprite(_SupportsSprite): def remove(self, *groups: _Group) -> None: ... def kill(self) -> None: ... def alive(self) -> bool: ... - def groups(self) -> List[_Group]: ... + def groups(self) -> list[_Group]: ... # concrete dirty sprite implementation class class DirtySprite(_SupportsDirtySprite): @@ -147,8 +142,8 @@ _TDirtySprite = TypeVar("_TDirtySprite", bound=_DirtySpriteSupportsGroup) # b = Group(MySprite()) class AbstractGroup(Generic[_TSprite]): - spritedict: Dict[_TSprite, Optional[Union[FRect, Rect]]] - lostsprites: List[Union[FRect, Rect]] + spritedict: dict[_TSprite, Optional[Union[FRect, Rect]]] + lostsprites: list[Union[FRect, Rect]] def __init__(self) -> None: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_TSprite]: ... @@ -158,7 +153,7 @@ class AbstractGroup(Generic[_TSprite]): def remove_internal(self, sprite: _TSprite) -> None: ... def has_internal(self, sprite: _TSprite) -> bool: ... def copy(self: _TGroup) -> _TGroup: ... # typing.Self is py3.11+ - def sprites(self) -> List[_TSprite]: ... + def sprites(self) -> list[_TSprite]: ... def add( self, *sprites: Union[_TSprite, AbstractGroup[_TSprite], Iterable[_TSprite]] ) -> None: ... @@ -169,7 +164,7 @@ class AbstractGroup(Generic[_TSprite]): self, *sprites: Union[_TSprite, AbstractGroup[_TSprite], Iterable[_TSprite]] ) -> bool: ... def update(self, *args: Any, **kwargs: Any) -> None: ... - def draw(self, surface: Surface) -> List[Union[FRect, Rect]]: ... + def draw(self, surface: Surface) -> list[Union[FRect, Rect]]: ... def clear( self, surface: Surface, @@ -211,10 +206,10 @@ class LayeredUpdates(AbstractGroup[_TSprite]): ], **kwargs: Any ) -> None: ... - def get_sprites_at(self, pos: Point) -> List[_TSprite]: ... + def get_sprites_at(self, pos: Point) -> list[_TSprite]: ... def get_sprite(self, idx: int) -> _TSprite: ... - def remove_sprites_of_layer(self, layer_nr: int) -> List[_TSprite]: ... - def layers(self) -> List[int]: ... + def remove_sprites_of_layer(self, layer_nr: int) -> list[_TSprite]: ... + def layers(self) -> list[int]: ... def change_layer(self, sprite: _TSprite, new_layer: int) -> None: ... def get_layer_of_sprite(self, sprite: _TSprite) -> int: ... def get_top_layer(self) -> int: ... @@ -222,14 +217,14 @@ class LayeredUpdates(AbstractGroup[_TSprite]): def move_to_front(self, sprite: _TSprite) -> None: ... def move_to_back(self, sprite: _TSprite) -> None: ... def get_top_sprite(self) -> _TSprite: ... - def get_sprites_from_layer(self, layer: int) -> List[_TSprite]: ... + def get_sprites_from_layer(self, layer: int) -> list[_TSprite]: ... def switch_layer(self, layer1_nr: int, layer2_nr: int) -> None: ... class LayeredDirty(LayeredUpdates[_TDirtySprite]): def __init__(self, *sprites: _TDirtySprite, **kwargs: Any) -> None: ... def draw( self, surface: Surface, bgd: Optional[Surface] = None - ) -> List[Union[FRect, Rect]]: ... + ) -> list[Union[FRect, Rect]]: ... # clear breaks Liskov substitution principle in code def clear(self, surface: Surface, bgd: Surface) -> None: ... # type: ignore[override] def repaint_rect(self, screen_rect: RectLike) -> None: ... @@ -275,20 +270,20 @@ _SupportsCollideMask = Union[_HasImageAndRect, _HasMaskAndRect] def collide_mask( left: _SupportsCollideMask, right: _SupportsCollideMask -) -> Optional[Tuple[int, int]]: ... +) -> Optional[tuple[int, int]]: ... def spritecollide( sprite: _HasRect, group: AbstractGroup[_TSprite], dokill: bool, collided: Optional[Callable[[_TSprite, _TSprite2], Any]] = None, -) -> List[_TSprite]: ... +) -> list[_TSprite]: ... def groupcollide( groupa: AbstractGroup[_TSprite], groupb: AbstractGroup[_TSprite2], dokilla: bool, dokillb: bool, collided: Optional[Callable[[_TSprite, _TSprite2], Any]] = None, -) -> Dict[_TSprite, List[_TSprite2]]: ... +) -> dict[_TSprite, list[_TSprite2]]: ... def spritecollideany( sprite: _HasRect, group: AbstractGroup[_TSprite], diff --git a/buildconfig/stubs/pygame/surface.pyi b/buildconfig/stubs/pygame/surface.pyi index 535f5d776e..f68154afa9 100644 --- a/buildconfig/stubs/pygame/surface.pyi +++ b/buildconfig/stubs/pygame/surface.pyi @@ -1,5 +1,6 @@ -from typing import Any, Iterable, List, Literal, Optional, Tuple, Union, overload -from typing_extensions import deprecated # added in 3.13 +from collections.abc import Iterable +from typing import Any, Literal, Optional, Union, overload +from typing_extensions import deprecated # added in 3.13 from pygame.bufferproxy import BufferProxy from pygame.color import Color @@ -46,7 +47,7 @@ class Surface: @property def height(self) -> int: ... @property - def size(self) -> Tuple[int, int]: ... + def size(self) -> tuple[int, int]: ... @overload def __init__( self, @@ -76,16 +77,16 @@ class Surface: self, blit_SequenceLike: Iterable[ Union[ - Tuple[Surface, Union[Point, RectLike]], - Tuple[Surface, Union[Point, RectLike], Union[RectLike, int]], - Tuple[Surface, Union[Point, RectLike], RectLike, int], + tuple[Surface, Union[Point, RectLike]], + tuple[Surface, Union[Point, RectLike], Union[RectLike, int]], + tuple[Surface, Union[Point, RectLike], RectLike, int], ] ], doreturn: Union[int, bool] = 1, - ) -> Union[List[Rect], None]: ... + ) -> Union[list[Rect], None]: ... def fblits( self, - blit_SequenceLike: Iterable[Tuple[Surface, Union[Point, RectLike]]], + blit_SequenceLike: Iterable[tuple[Surface, Union[Point, RectLike]]], special_flags: int = 0, / ) -> None: ... @overload @@ -108,7 +109,7 @@ class Surface: def set_colorkey(self, color: ColorLike, flags: int = 0, /) -> None: ... @overload def set_colorkey(self, color: None, /) -> None: ... - def get_colorkey(self) -> Optional[Tuple[int, int, int, int]]: ... + def get_colorkey(self) -> Optional[tuple[int, int, int, int]]: ... @overload def set_alpha(self, value: int, flags: int = 0, /) -> None: ... @overload @@ -118,11 +119,11 @@ class Surface: def unlock(self) -> None: ... def mustlock(self) -> bool: ... def get_locked(self) -> bool: ... - def get_locks(self) -> Tuple[Any, ...]: ... + def get_locks(self) -> tuple[Any, ...]: ... def get_at(self, x_y: Point, /) -> Color: ... def set_at(self, x_y: Point, color: ColorLike, /) -> None: ... def get_at_mapped(self, x_y: Point, /) -> int: ... - def get_palette(self) -> List[Color]: ... + def get_palette(self) -> list[Color]: ... def get_palette_at(self, index: int, /) -> Color: ... def set_palette(self, palette: SequenceLike[ColorLike], /) -> None: ... def set_palette_at(self, index: int, color: ColorLike, /) -> None: ... @@ -140,9 +141,9 @@ class Surface: ) -> Surface: ... def get_parent(self) -> Surface: ... def get_abs_parent(self) -> Surface: ... - def get_offset(self) -> Tuple[int, int]: ... - def get_abs_offset(self) -> Tuple[int, int]: ... - def get_size(self) -> Tuple[int, int]: ... + def get_offset(self) -> tuple[int, int]: ... + def get_abs_offset(self) -> tuple[int, int]: ... + def get_size(self) -> tuple[int, int]: ... def get_width(self) -> int: ... def get_height(self) -> int: ... def get_rect(self, **kwargs: Any) -> Rect: ... @@ -151,13 +152,13 @@ class Surface: def get_bytesize(self) -> int: ... def get_flags(self) -> int: ... def get_pitch(self) -> int: ... - def get_masks(self) -> Tuple[int, int, int, int]: ... + def get_masks(self) -> tuple[int, int, int, int]: ... @deprecated("since 2.0.0. Immutable in SDL2") def set_masks(self, color: ColorLike, /) -> None: ... - def get_shifts(self) -> Tuple[int, int, int, int]: ... + def get_shifts(self) -> tuple[int, int, int, int]: ... @deprecated("since 2.0.0. Immutable in SDL2") def set_shifts(self, color: ColorLike, /) -> None: ... - def get_losses(self) -> Tuple[int, int, int, int]: ... + def get_losses(self) -> tuple[int, int, int, int]: ... def get_bounding_rect(self, min_alpha: int = 1) -> Rect: ... def get_view(self, kind: _ViewKind = "2", /) -> BufferProxy: ... def get_buffer(self) -> BufferProxy: ... diff --git a/buildconfig/stubs/pygame/surfarray.pyi b/buildconfig/stubs/pygame/surfarray.pyi index c15f089518..bafe709376 100644 --- a/buildconfig/stubs/pygame/surfarray.pyi +++ b/buildconfig/stubs/pygame/surfarray.pyi @@ -1,4 +1,3 @@ -from typing import Tuple from typing_extensions import deprecated # added in 3.13 import numpy @@ -32,4 +31,4 @@ def use_arraytype(arraytype: str) -> None: ... @deprecated("Only numpy is supported") def get_arraytype() -> str: ... @deprecated("Only numpy is supported") -def get_arraytypes() -> Tuple[str]: ... +def get_arraytypes() -> tuple[str]: ... diff --git a/buildconfig/stubs/pygame/system.pyi b/buildconfig/stubs/pygame/system.pyi index f2e367473f..514af9a134 100644 --- a/buildconfig/stubs/pygame/system.pyi +++ b/buildconfig/stubs/pygame/system.pyi @@ -1,4 +1,4 @@ -from typing import List, Optional, TypedDict +from typing import Optional, TypedDict from pygame._data_classes import PowerState @@ -26,5 +26,5 @@ class _Locale(TypedDict): def get_cpu_instruction_sets() -> _InstructionSets: ... def get_total_ram() -> int: ... def get_pref_path(org: str, app: str) -> str: ... -def get_pref_locales() -> List[_Locale]: ... +def get_pref_locales() -> list[_Locale]: ... def get_power_state() -> Optional[PowerState]: ... diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index f1a5f27918..384b41d3ac 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -1,4 +1,4 @@ -from typing import Optional, Union, Literal, Tuple +from typing import Optional, Union, Literal from pygame.surface import Surface @@ -47,7 +47,7 @@ def average_surfaces( ) -> Surface: ... def average_color( surface: Surface, rect: Optional[RectLike] = None, consider_alpha: bool = False -) -> Tuple[int, int, int, int]: ... +) -> tuple[int, int, int, int]: ... def threshold( dest_surface: Optional[Surface], surface: Surface, diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 45d793a4ac..3499bbffd5 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -12,18 +12,10 @@ __all__ = [ "IntPoint", ] -import sys from abc import abstractmethod -from typing import IO, Callable, Tuple, Union, TypeVar, Protocol - -if sys.version_info >= (3, 9): - from os import PathLike as _PathProtocol -else: - _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) - - class _PathProtocol(Protocol[_AnyStr_co]): - @abstractmethod - def __fspath__(self) -> _AnyStr_co: ... +from collections.abc import Callable +from os import PathLike as _PathProtocol +from typing import IO, Union, TypeVar, Protocol # For functions that take a file name @@ -67,4 +59,4 @@ RectLike = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute] # cleanup namespace -del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol +del abstractmethod, IO, Callable, Union, TypeVar, Protocol diff --git a/buildconfig/stubs/pygame/version.pyi b/buildconfig/stubs/pygame/version.pyi index 3838d68274..4de5eb29e3 100644 --- a/buildconfig/stubs/pygame/version.pyi +++ b/buildconfig/stubs/pygame/version.pyi @@ -1,6 +1,6 @@ -from typing import Literal, Tuple +from typing import Literal -class SoftwareVersion(Tuple[int, int, int]): +class SoftwareVersion(tuple[int, int, int]): def __new__(cls, major: int, minor: int, patch: int) -> SoftwareVersion: ... def __repr__(self) -> str: ... def __str__(self) -> str: ... @@ -10,7 +10,7 @@ class SoftwareVersion(Tuple[int, int, int]): def minor(self) -> int: ... @property def patch(self) -> int: ... - fields: Tuple[Literal["major"], Literal["minor"], Literal["patch"]] + fields: tuple[Literal["major"], Literal["minor"], Literal["patch"]] class PygameVersion(SoftwareVersion): ... class SDLVersion(SoftwareVersion): ... diff --git a/buildconfig/stubs/pygame/window.pyi b/buildconfig/stubs/pygame/window.pyi index 69d04b3b36..338129bb70 100644 --- a/buildconfig/stubs/pygame/window.pyi +++ b/buildconfig/stubs/pygame/window.pyi @@ -1,4 +1,4 @@ -from typing import Optional, Tuple, Union +from typing import Optional, Union from typing_extensions import deprecated # added in 3.13 from pygame.typing import Point, RectLike @@ -53,19 +53,19 @@ class Window: @mouse_rect.setter def mouse_rect(self, value: Optional[RectLike]) -> None: ... @property - def size(self) -> Tuple[int, int]: ... + def size(self) -> tuple[int, int]: ... @size.setter def size(self, value: Point) -> None: ... @property - def minimum_size(self) -> Tuple[int, int]: ... + def minimum_size(self) -> tuple[int, int]: ... @minimum_size.setter def minimum_size(self, value: Point) -> None: ... @property - def maximum_size(self) -> Tuple[int, int]: ... + def maximum_size(self) -> tuple[int, int]: ... @maximum_size.setter def maximum_size(self, value: Point) -> None: ... @property - def position(self) -> Tuple[int, int]: ... + def position(self) -> tuple[int, int]: ... @position.setter def position(self, value: Union[int, Point]) -> None: ... @property diff --git a/src_py/typing.py b/src_py/typing.py index 45d793a4ac..3499bbffd5 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -12,18 +12,10 @@ "IntPoint", ] -import sys from abc import abstractmethod -from typing import IO, Callable, Tuple, Union, TypeVar, Protocol - -if sys.version_info >= (3, 9): - from os import PathLike as _PathProtocol -else: - _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) - - class _PathProtocol(Protocol[_AnyStr_co]): - @abstractmethod - def __fspath__(self) -> _AnyStr_co: ... +from collections.abc import Callable +from os import PathLike as _PathProtocol +from typing import IO, Union, TypeVar, Protocol # For functions that take a file name @@ -67,4 +59,4 @@ def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... # cleanup namespace -del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol +del abstractmethod, IO, Callable, Union, TypeVar, Protocol