Skip to content

Commit

Permalink
Use python 3.9isms in typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Nov 5, 2024
1 parent ed45647 commit ff42cdf
Show file tree
Hide file tree
Showing 38 changed files with 232 additions and 288 deletions.
7 changes: 4 additions & 3 deletions buildconfig/stubs/pygame/_debug.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
4 changes: 2 additions & 2 deletions buildconfig/stubs/pygame/_sdl2/audio.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, List
from collections.abc import Callable

AUDIO_U8: int
AUDIO_S8: int
Expand All @@ -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__(
Expand Down
5 changes: 3 additions & 2 deletions buildconfig/stubs/pygame/_sdl2/controller_old.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Dict, Mapping, Optional
from collections.abc import Mapping
from typing import Optional

from pygame.joystick import JoystickType

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions buildconfig/stubs/pygame/_sdl2/touch.pyi
Original file line number Diff line number Diff line change
@@ -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]]: ...
10 changes: 5 additions & 5 deletions buildconfig/stubs/pygame/_sdl2/video.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand All @@ -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: ...
Expand All @@ -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,
Expand Down Expand Up @@ -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: ...
7 changes: 4 additions & 3 deletions buildconfig/stubs/pygame/base.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Tuple, Callable
from collections.abc import Callable
from typing import Any

__version__: str

Expand All @@ -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: ...

Expand Down
4 changes: 2 additions & 2 deletions buildconfig/stubs/pygame/bufferproxy.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any, Dict, overload
from typing import Any, overload

class BufferProxy:
parent: Any
length: int
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: ...
Expand Down
14 changes: 7 additions & 7 deletions buildconfig/stubs/pygame/camera.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand All @@ -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
Expand All @@ -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: ...
37 changes: 16 additions & 21 deletions buildconfig/stubs/pygame/color.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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: ...
Expand All @@ -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: ...
Expand Down
17 changes: 9 additions & 8 deletions buildconfig/stubs/pygame/cursors.pyi
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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],
]
23 changes: 12 additions & 11 deletions buildconfig/stubs/pygame/display.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit ff42cdf

Please sign in to comment.