diff --git a/README.rst b/README.rst index a0347341e7..f0fcc4fac0 100644 --- a/README.rst +++ b/README.rst @@ -139,7 +139,7 @@ Dependency versions: +----------+------------------------+ -| CPython | >= 3.8 (Or use PyPy3) | +| CPython | >= 3.9 (Or use PyPy3) | +----------+------------------------+ | SDL | >= 2.0.14 | +----------+------------------------+ 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..7f8ed1a6b7 100644 --- a/buildconfig/stubs/pygame/event.pyi +++ b/buildconfig/stubs/pygame/event.pyi @@ -1,28 +1,24 @@ -from typing import ( - Any, - Dict, - List, - Optional, - Union, - final, -) +from typing import Any, Optional, Union, final from pygame.typing import SequenceLike @final class Event: type: int - dict: Dict[str, Any] - __dict__: Dict[str, Any] + __dict__: dict[str, Any] __hash__: None # type: ignore def __init__( - self, type: int, dict: Dict[str, Any] = ..., **kwargs: Any + self, type: int, dict: dict[str, Any] = ..., **kwargs: Any ) -> None: ... def __getattribute__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... def __delattr__(self, name: str) -> None: ... def __bool__(self) -> bool: ... + # this is at the bottom because mypy complains if this declaration comes + # before any uses of the dict[] typehinting because of the same naming + dict: dict[str, Any] + _EventTypes = Union[int, SequenceLike[int]] def pump() -> None: ... @@ -30,7 +26,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 d21842a494..efbf54a23a 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -1,11 +1,5 @@ -from typing import ( - overload, - Union, - Callable, - Protocol, - Tuple, - List, -) +from collections.abc import Callable +from typing import overload, Union, Protocol from pygame import Rect, FRect from pygame.typing import Point, RectLike, SequenceLike @@ -17,7 +11,7 @@ class _HasCircleAttribute(Protocol): def circle(self) -> Union[_CircleLike, Callable[[], _CircleLike]]: ... _CircleLike = Union[ - Circle, Tuple[Point, float], SequenceLike[float], _HasCircleAttribute + Circle, tuple[Point, float], SequenceLike[float], _HasCircleAttribute ] class _HasLineAttribute(Protocol): @@ -69,23 +63,23 @@ 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 - def top(self) -> Tuple[float, float]: ... + def top(self) -> tuple[float, float]: ... @top.setter def top(self, value: Point) -> None: ... @property - def left(self) -> Tuple[float, float]: ... + def left(self) -> tuple[float, float]: ... @left.setter def left(self, value: Point) -> None: ... @property - def bottom(self) -> Tuple[float, float]: ... + def bottom(self) -> tuple[float, float]: ... @bottom.setter def bottom(self, value: Point) -> None: ... @property - def right(self) -> Tuple[float, float]: ... + def right(self) -> tuple[float, float]: ... @right.setter def right(self, value: Point) -> None: ... @overload @@ -120,8 +114,10 @@ class Circle: def colliderect(self, topleft: Point, size: Point, /) -> bool: ... def collideswith(self, other: _CanBeCollided, /) -> bool: ... def collidelist(self, colliders: SequenceLike[_CanBeCollided], /) -> int: ... - def collidelistall(self, colliders: SequenceLike[_CanBeCollided], /) -> List[int]: ... - def intersect(self, other: _CanBeIntersected, /) -> List[Tuple[float, float]]: ... + def collidelistall( + self, colliders: SequenceLike[_CanBeCollided], / + ) -> list[int]: ... + def intersect(self, other: _CanBeIntersected, /) -> list[tuple[float, float]]: ... def contains(self, shape: _CanBeCollided, /) -> bool: ... @overload def update(self, circle: _CircleLike, /) -> None: ... @@ -160,11 +156,11 @@ class Line: @by.setter def by(self, value: float) -> None: ... @property - def a(self) -> Tuple[float, float]: ... + def a(self) -> tuple[float, float]: ... @a.setter def a(self, value: Point) -> None: ... @property - def b(self) -> Tuple[float, float]: ... + def b(self) -> tuple[float, float]: ... @b.setter def b(self, value: Point) -> None: ... @overload 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 a32c840eba..98425b8adf 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 @@ -110,7 +111,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 @@ -120,11 +121,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: ... @@ -142,9 +143,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: ... @@ -153,13 +154,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 ca88863a59..2897a338fe 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -12,24 +12,15 @@ __all__ = [ "IntPoint", ] -import sys from abc import abstractmethod -from typing import IO, Callable, Tuple, Union, TypeVar, Protocol +from collections.abc import Callable +from os import PathLike as _PathProtocol +from typing import IO, Union, TypeVar, Protocol from pygame.color import Color from pygame.rect import Rect, FRect -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: ... - - # For functions that take a file name _PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]] # Most pygame functions that take a file argument should be able to handle a FileLike type @@ -74,14 +65,12 @@ RectLike = Union[ # cleanup namespace del ( - sys, abstractmethod, Color, Rect, FRect, IO, Callable, - Tuple, 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/docs/reST/ref/sprite.rst b/docs/reST/ref/sprite.rst index 268727a1d0..a1e96a71c9 100644 --- a/docs/reST/ref/sprite.rst +++ b/docs/reST/ref/sprite.rst @@ -291,7 +291,7 @@ Sprites are not thread safe. So lock them yourself if using threads. .. method:: draw | :sl:`blit the Sprite images` - | :sg:`draw(Surface) -> List[Rect]` + | :sg:`draw(Surface) -> list[Rect]` Draws the contained Sprites to the Surface argument. This uses the ``Sprite.image`` attribute for the source surface, and ``Sprite.rect`` diff --git a/docs/readmes/README.es.rst b/docs/readmes/README.es.rst index d1ca1fd6c2..205ea5b14c 100644 --- a/docs/readmes/README.es.rst +++ b/docs/readmes/README.es.rst @@ -117,7 +117,7 @@ El módulo surfarray necesita el paquete python numpy, para sus matrices numéri Versiones de dependencia: +----------+-----------------------------+ -| CPython | >= 3.8 (Ou utiliser PyPy3) | +| CPython | >= 3.9 (Ou utiliser PyPy3) | +----------+-----------------------------+ | SDL | >= 2.0.14 | +----------+-----------------------------+ diff --git a/docs/readmes/README.fa.rst b/docs/readmes/README.fa.rst index b3b7229b33..99c70fdcba 100644 --- a/docs/readmes/README.fa.rst +++ b/docs/readmes/README.fa.rst @@ -189,7 +189,7 @@ Dependencies (وابستگی ها) مشاهده کنید. +----------+------------------------+ -| CPython | >= 3.8 (Or use PyPy3) | +| CPython | >= 3.9 (Or use PyPy3) | +----------+------------------------+ | SDL | >= 2.0.14 | +----------+------------------------+ diff --git a/docs/readmes/README.fr.rst b/docs/readmes/README.fr.rst index c17d701fa9..e77a2376c6 100644 --- a/docs/readmes/README.fr.rst +++ b/docs/readmes/README.fr.rst @@ -146,7 +146,7 @@ multidimensionnels. Versions des dépendances: +----------+-----------------------------+ -| CPython | >= 3.8 (Ou utiliser PyPy3) | +| CPython | >= 3.9 (Ou utiliser PyPy3) | +----------+-----------------------------+ | SDL | >= 2.0.14 | +----------+-----------------------------+ diff --git a/docs/readmes/README.it.rst b/docs/readmes/README.it.rst index f660b2c3cc..496eeb8b11 100644 --- a/docs/readmes/README.it.rst +++ b/docs/readmes/README.it.rst @@ -140,7 +140,7 @@ Le versioni dei requisiti: +----------+------------------------+ -| CPython | >= 3.8 (Or use PyPy3) | +| CPython | >= 3.9 (Or use PyPy3) | +----------+------------------------+ | SDL | >= 2.0.14 | +----------+------------------------+ diff --git a/docs/readmes/README.ja.rst b/docs/readmes/README.ja.rst index 502cd98e8e..be55955dcc 100644 --- a/docs/readmes/README.ja.rst +++ b/docs/readmes/README.ja.rst @@ -151,7 +151,7 @@ gfxdraw には SDL_gfx の埋め込みバージョンが含まれています。 依存バージョン: +----------+------------------------+ -| CPython | >= 3.8 (Or use PyPy3) | +| CPython | >= 3.9 (Or use PyPy3) | +----------+------------------------+ | SDL | >= 2.0.14 | +----------+------------------------+ diff --git a/docs/readmes/README.ru.rst b/docs/readmes/README.ru.rst index cdcbd37fc7..57eea35501 100644 --- a/docs/readmes/README.ru.rst +++ b/docs/readmes/README.ru.rst @@ -141,7 +141,7 @@ SDL_rotozoom, а gfxdraw имеет встроенную версию SDL_gfx. +----------+------------------------+ -| CPython | >= 3.8 (Or use PyPy3) | +| CPython | >= 3.9 (Or use PyPy3) | +----------+------------------------+ | SDL | >= 2.0.14 | +----------+------------------------+ diff --git a/docs/readmes/README.zh-cn.rst b/docs/readmes/README.zh-cn.rst index 63745b8edb..98fec8dadd 100644 --- a/docs/readmes/README.zh-cn.rst +++ b/docs/readmes/README.zh-cn.rst @@ -105,7 +105,7 @@ pygame显然依赖于SDL和Python。此外pygame还嵌入了几个较小的库 +----------+------------------------+ -| CPython | >= 3.8 (或 PyPy3) | +| CPython | >= 3.9 (或 PyPy3) | +----------+------------------------+ | SDL | >= 2.0.14 | +----------+------------------------+ diff --git a/examples/stars.py b/examples/stars.py index 0b7bd32942..0b63d922f4 100644 --- a/examples/stars.py +++ b/examples/stars.py @@ -11,7 +11,6 @@ """ import random -from typing import List import pygame @@ -19,7 +18,7 @@ class Particle: def __init__( self, - pos: List[int], + pos: list[int], vel: pygame.Vector2, ): """ @@ -55,7 +54,7 @@ def update(self): self.pos += self.vel -def create_particle(particle_list: List[Particle], pos: pygame.Vector2): +def create_particle(particle_list: list[Particle], pos: pygame.Vector2): """ Creates a new particle Parameters: @@ -71,7 +70,7 @@ def create_particle(particle_list: List[Particle], pos: pygame.Vector2): ) -def update_particles(particle_list: List[Particle], screen_rect: pygame.Rect): +def update_particles(particle_list: list[Particle], screen_rect: pygame.Rect): """ Updates the particles Parameters: @@ -87,7 +86,7 @@ def update_particles(particle_list: List[Particle], screen_rect: pygame.Rect): particle.update() -def draw_particles(particle_list: List[Particle], display: pygame.Surface): +def draw_particles(particle_list: list[Particle], display: pygame.Surface): """ Draws the particles Parameters: diff --git a/examples/textinput.py b/examples/textinput.py index 76cfb38902..c783de8bd8 100644 --- a/examples/textinput.py +++ b/examples/textinput.py @@ -6,7 +6,6 @@ Shows how to use the TEXTEDITING and TEXTINPUT events. """ -from typing import Tuple, List import sys import os @@ -39,8 +38,8 @@ class TextInput: def __init__( self, prompt: str, - pos: Tuple[int, int], - screen_dimensions: Tuple[int, int], + pos: tuple[int, int], + screen_dimensions: tuple[int, int], print_event: bool, text_color="white", fps: int = 50, @@ -77,7 +76,7 @@ def __init__( print("Using font: " + self.font.name) - def update(self, events: List[pygame.Event]) -> None: + def update(self, events: list[pygame.Event]) -> None: """ Updates the text input widget """ diff --git a/pyproject.toml b/pyproject.toml index 476a08242e..d2d3ea2f4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "pygame-ce" version = "2.5.3.dev1" description = "Python Game Development" readme = "README.rst" # for long description -requires-python = ">=3.8" +requires-python = ">=3.9" license = {text = "LGPL v2.1"} authors = [{name = "A community project"}] classifiers = [ @@ -14,7 +14,6 @@ classifiers = [ "Programming Language :: Cython", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -74,7 +73,7 @@ install = ['--tags=runtime,python-runtime,pg-tag'] # dependencies. Here is where uv comes into the picture. It is an "installer" like pip, # but faster. It has been observed to save a couple of minutes of CI time. build-frontend = "build[uv]" -build = "cp3{8,9,10,11,12,13}-* pp3{8,9,10}-*" +build = "cp3{9,10,11,12,13}-* pp3{9,10}-*" skip = "*-musllinux_*" # build[uv] is verbose by default, so below flag is not needed here # build-verbosity = 3 diff --git a/setup.cfg b/setup.cfg index 1c71cfb797..c3fdd9f9d5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [tox:tox] -envlist = py{38,39,310,311,312,313} +envlist = py{39,310,311,312,313} skip_missing_interpreters = True skipsdist = True diff --git a/setup.py b/setup.py index cbad740727..001edc3e2c 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,6 @@ "Programming Language :: Cython", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -63,7 +62,7 @@ "Operating System :: MacOS", "Typing :: Typed" ], - "python_requires": '>=3.8', + "python_requires": '>=3.9', } import re @@ -156,11 +155,11 @@ def compilation_help(): print('---\n') -if not hasattr(sys, 'version_info') or sys.version_info < (3, 8): +if not hasattr(sys, 'version_info') or sys.version_info < (3, 9): compilation_help() - raise SystemExit("Pygame-ce requires Python3 version 3.8 or above.") + raise SystemExit("Pygame-ce requires Python3 version 3.9 or above.") if IS_PYPY and sys.pypy_version_info < (7,): - raise SystemExit("Pygame-ce requires PyPy version 7.0.0 above, compatible with CPython >= 3.8") + raise SystemExit("Pygame-ce requires PyPy version 7.0.0 above, compatible with CPython >= 3.9") def consume_arg(name): diff --git a/src_c/cython/pygame/_sdl2/audio.pyx b/src_c/cython/pygame/_sdl2/audio.pyx index c3667d5e32..97c6504a08 100644 --- a/src_c/cython/pygame/_sdl2/audio.pyx +++ b/src_c/cython/pygame/_sdl2/audio.pyx @@ -51,7 +51,7 @@ def get_audio_device_names(iscapture = False): If True return devices available for capture. :return: list of devicenames. - :rtype: List[string] + :rtype: list[string] """ cdef int count = SDL_GetNumAudioDevices(iscapture) diff --git a/src_c/doc/sprite_doc.h b/src_c/doc/sprite_doc.h index 86e61f3565..857f1c6d70 100644 --- a/src_c/doc/sprite_doc.h +++ b/src_c/doc/sprite_doc.h @@ -15,7 +15,7 @@ #define DOC_SPRITE_GROUP_REMOVE "remove(*sprites) -> None\nremove Sprites from the Group" #define DOC_SPRITE_GROUP_HAS "has(*sprites) -> bool\ntest if a Group contains Sprites" #define DOC_SPRITE_GROUP_UPDATE "update(*args, **kwargs) -> None\ncall the update method on contained Sprites" -#define DOC_SPRITE_GROUP_DRAW "draw(Surface) -> List[Rect]\nblit the Sprite images" +#define DOC_SPRITE_GROUP_DRAW "draw(Surface) -> list[Rect]\nblit the Sprite images" #define DOC_SPRITE_GROUP_CLEAR "clear(Surface_dest, background) -> None\ndraw a background over the Sprites" #define DOC_SPRITE_GROUP_EMPTY "empty() -> None\nremove all Sprites" #define DOC_SPRITE_RENDERUPDATES "RenderUpdates(*sprites) -> RenderUpdates\nGroup sub-class that tracks dirty updates." diff --git a/src_py/_debug.py b/src_py/_debug.py index 3d39850a60..c8d73fa512 100644 --- a/src_py/_debug.py +++ b/src_py/_debug.py @@ -4,13 +4,14 @@ import sys import traceback import importlib -from typing import Tuple, Optional, Callable +from collections.abc import Callable +from typing import Optional from os import environ from pygame.version import ver from pygame.system import get_cpu_instruction_sets -ImportResult = Tuple[str, bool, Optional[Callable]] +ImportResult = tuple[str, bool, Optional[Callable]] def str_from_tuple(version_tuple): diff --git a/src_py/pkgdata.py b/src_py/pkgdata.py index 8076900e3e..7cff0c383f 100644 --- a/src_py/pkgdata.py +++ b/src_py/pkgdata.py @@ -22,27 +22,16 @@ def getResource(identifier, pkgname=__name__): import os try: - if sys.version_info[:2] > (3, 8): - from importlib.resources import files - - def resource_exists(_package_or_requirement, _resource_name): - _package_or_requirement = _package_or_requirement.split(".")[0] - return files(_package_or_requirement).joinpath(_resource_name).is_file() - - def resource_stream(_package_or_requirement, _resource_name): - _package_or_requirement = _package_or_requirement.split(".")[0] - ref = files(_package_or_requirement).joinpath(_resource_name) - return ref.open('rb') - else: - from importlib import resources - - def resource_exists(_package_or_requirement, _resource_name): - _package_or_requirement = _package_or_requirement.split(".")[0] - return resources.is_resource(_package_or_requirement, _resource_name) # pylint: disable=deprecated-method - - def resource_stream(_package_or_requirement, _resource_name): - _package_or_requirement = _package_or_requirement.split(".")[0] - return resources.open_binary(_package_or_requirement, _resource_name) # pylint: disable=deprecated-method + from importlib.resources import files + + def resource_exists(_package_or_requirement, _resource_name): + _package_or_requirement = _package_or_requirement.split(".")[0] + return files(_package_or_requirement).joinpath(_resource_name).is_file() + + def resource_stream(_package_or_requirement, _resource_name): + _package_or_requirement = _package_or_requirement.split(".")[0] + ref = files(_package_or_requirement).joinpath(_resource_name) + return ref.open("rb") except ImportError: diff --git a/src_py/typing.py b/src_py/typing.py index ca88863a59..2897a338fe 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -12,24 +12,15 @@ "IntPoint", ] -import sys from abc import abstractmethod -from typing import IO, Callable, Tuple, Union, TypeVar, Protocol +from collections.abc import Callable +from os import PathLike as _PathProtocol +from typing import IO, Union, TypeVar, Protocol from pygame.color import Color from pygame.rect import Rect, FRect -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: ... - - # For functions that take a file name _PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]] # Most pygame functions that take a file argument should be able to handle a FileLike type @@ -74,14 +65,12 @@ def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... # cleanup namespace del ( - sys, abstractmethod, Color, Rect, FRect, IO, Callable, - Tuple, Union, TypeVar, Protocol,