From 19e29f4b8af1f518555ad8c33bcfc918a01ce6a7 Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:27:52 -0800 Subject: [PATCH 1/3] Mark old xType aliases as deprecated Doesn't touch JoystickType because the C code still works the old way I think, doesn't touch CameraType because CameraType is not in the stubs. In fact CameraType might be removable as an internal implementation detail. --- buildconfig/stubs/pygame/event.pyi | 30 ++++++++++++++++++++++++++-- buildconfig/stubs/pygame/font.pyi | 4 +++- buildconfig/stubs/pygame/mask.pyi | 4 +++- buildconfig/stubs/pygame/mixer.pyi | 8 ++++++-- buildconfig/stubs/pygame/rect.pyi | 8 ++++++-- buildconfig/stubs/pygame/surface.pyi | 3 ++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/buildconfig/stubs/pygame/event.pyi b/buildconfig/stubs/pygame/event.pyi index 1ad71ac57a..2fa1081f5b 100644 --- a/buildconfig/stubs/pygame/event.pyi +++ b/buildconfig/stubs/pygame/event.pyi @@ -1,9 +1,37 @@ from typing import Any, Optional, Union, final +from typing_extensions import deprecated # added in 3.13 from pygame.typing import SequenceLike @final class Event: + # Event fields here duplicated below into EventType because Event is + # marked as final and can't be subclassed like the other xType aliases + # are to allow @deprecated. + + @property + def type(self) -> int: ... + __dict__: dict[str, Any] + __hash__: None # type: ignore + def __init__( + 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 + @property + def dict(self) -> dict[str, Any]: ... + +@final +@deprecated("Use `Event` instead (this is an old alias)") +class EventType: + # Duplicated Event fields here because it is marked as final and can't be + # subclassed like the other xType aliases are to allow @deprecated. + @property def type(self) -> int: ... __dict__: dict[str, Any] @@ -41,5 +69,3 @@ def set_grab(grab: bool, /) -> None: ... def get_grab() -> bool: ... def post(event: Event, /) -> bool: ... def custom_type() -> int: ... - -EventType = Event diff --git a/buildconfig/stubs/pygame/font.pyi b/buildconfig/stubs/pygame/font.pyi index 931d8ceeba..0a313920c7 100644 --- a/buildconfig/stubs/pygame/font.pyi +++ b/buildconfig/stubs/pygame/font.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable, Hashable, Iterable from typing import Literal, Optional, Union +from typing_extensions import deprecated # added in 3.13 from pygame.surface import Surface @@ -87,4 +88,5 @@ class Font: def get_point_size(self) -> int: ... def set_point_size(self, val: int, /) -> None: ... -FontType = Font +@deprecated("Use `Font` instead (this is an old alias)") +class FontType(Font): ... diff --git a/buildconfig/stubs/pygame/mask.pyi b/buildconfig/stubs/pygame/mask.pyi index 18d6e4e69d..35763de6d7 100644 --- a/buildconfig/stubs/pygame/mask.pyi +++ b/buildconfig/stubs/pygame/mask.pyi @@ -1,4 +1,5 @@ from typing import Any, Optional, Union +from typing_extensions import deprecated # added in 3.13 from pygame.rect import Rect from pygame.surface import Surface @@ -54,4 +55,5 @@ class Mask: dest: Union[RectLike, Point] = (0, 0), ) -> Surface: ... -MaskType = Mask +@deprecated("Use `Mask` instead (this is an old alias)") +class MaskType(Mask): ... diff --git a/buildconfig/stubs/pygame/mixer.pyi b/buildconfig/stubs/pygame/mixer.pyi index 205679768c..3bf929326f 100644 --- a/buildconfig/stubs/pygame/mixer.pyi +++ b/buildconfig/stubs/pygame/mixer.pyi @@ -1,4 +1,5 @@ from typing import Any, Optional, Union, overload +from typing_extensions import deprecated # added in 3.13 import numpy @@ -100,5 +101,8 @@ class Channel: def set_endevent(self, type: Union[int, Event] = 0, /) -> None: ... def get_endevent(self) -> int: ... -SoundType = Sound -ChannelType = Channel +@deprecated("Use `Sound` instead (this is an old alias)") +class SoundType(Sound): ... + +@deprecated("Use `Channel` instead (this is an old alias)") +class ChannelType(Channel): ... diff --git a/buildconfig/stubs/pygame/rect.pyi b/buildconfig/stubs/pygame/rect.pyi index 72bf30b73f..9e0409e4c4 100644 --- a/buildconfig/stubs/pygame/rect.pyi +++ b/buildconfig/stubs/pygame/rect.pyi @@ -8,6 +8,7 @@ from typing import ( overload, Optional, ) +from typing_extensions import deprecated # added in 3.13 from pygame.typing import Point, RectLike, SequenceLike @@ -276,5 +277,8 @@ class Rect(_GenericRect[int]): class FRect(_GenericRect[float]): ... -RectType = Rect -FRectType = FRect +@deprecated("Use `Rect` instead (this is an old alias)") +class RectType(Rect): ... + +@deprecated("Use `FRect` instead (this is an old alias)") +class FRectType(FRect): ... diff --git a/buildconfig/stubs/pygame/surface.pyi b/buildconfig/stubs/pygame/surface.pyi index 98425b8adf..030e27904b 100644 --- a/buildconfig/stubs/pygame/surface.pyi +++ b/buildconfig/stubs/pygame/surface.pyi @@ -168,4 +168,5 @@ class Surface: def premul_alpha(self) -> Surface: ... def premul_alpha_ip(self) -> Surface: ... -SurfaceType = Surface +@deprecated("Use `Surface` instead (this is an old alias)") +class SurfaceType(Surface): ... From 65bb5654a4ea5ee47608cda1205c8076189cc889 Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Thu, 23 Jan 2025 22:01:02 -0800 Subject: [PATCH 2/3] Mark old types deprecated: don't duplicate event --- buildconfig/stubs/pygame/event.pyi | 34 ++++++++---------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/buildconfig/stubs/pygame/event.pyi b/buildconfig/stubs/pygame/event.pyi index 2fa1081f5b..6af37638e1 100644 --- a/buildconfig/stubs/pygame/event.pyi +++ b/buildconfig/stubs/pygame/event.pyi @@ -3,11 +3,9 @@ from typing_extensions import deprecated # added in 3.13 from pygame.typing import SequenceLike -@final -class Event: - # Event fields here duplicated below into EventType because Event is - # marked as final and can't be subclassed like the other xType aliases - # are to allow @deprecated. +class _GenericEvent: + # Just exists to avoid duplication of data for Event + # and (deprecated) EventType @property def type(self) -> int: ... @@ -27,27 +25,13 @@ class Event: def dict(self) -> dict[str, Any]: ... @final -@deprecated("Use `Event` instead (this is an old alias)") -class EventType: - # Duplicated Event fields here because it is marked as final and can't be - # subclassed like the other xType aliases are to allow @deprecated. - - @property - def type(self) -> int: ... - __dict__: dict[str, Any] - __hash__: None # type: ignore - def __init__( - 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: ... +class Event(_GenericEvent): + pass - # this is at the bottom because mypy complains if this declaration comes - # before any uses of the dict[] typehinting because of the same naming - @property - def dict(self) -> dict[str, Any]: ... +@final +@deprecated("Use `Event` instead (this is an old alias)") +class EventType(_GenericEvent): + pass _EventTypes = Union[int, SequenceLike[int]] From 1b2b195c567e7d03e42a712fff56e87d29b243fe Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Sat, 25 Jan 2025 00:56:31 -0800 Subject: [PATCH 3/3] Mark old types deprecated: clearer wording --- buildconfig/stubs/pygame/event.pyi | 2 +- buildconfig/stubs/pygame/font.pyi | 2 +- buildconfig/stubs/pygame/mask.pyi | 2 +- buildconfig/stubs/pygame/mixer.pyi | 4 ++-- buildconfig/stubs/pygame/rect.pyi | 4 ++-- buildconfig/stubs/pygame/surface.pyi | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/buildconfig/stubs/pygame/event.pyi b/buildconfig/stubs/pygame/event.pyi index 6af37638e1..b3c832bb03 100644 --- a/buildconfig/stubs/pygame/event.pyi +++ b/buildconfig/stubs/pygame/event.pyi @@ -29,7 +29,7 @@ class Event(_GenericEvent): pass @final -@deprecated("Use `Event` instead (this is an old alias)") +@deprecated("Use `Event` instead (EventType is an old alias)") class EventType(_GenericEvent): pass diff --git a/buildconfig/stubs/pygame/font.pyi b/buildconfig/stubs/pygame/font.pyi index 0a313920c7..efc72f0ae4 100644 --- a/buildconfig/stubs/pygame/font.pyi +++ b/buildconfig/stubs/pygame/font.pyi @@ -88,5 +88,5 @@ class Font: def get_point_size(self) -> int: ... def set_point_size(self, val: int, /) -> None: ... -@deprecated("Use `Font` instead (this is an old alias)") +@deprecated("Use `Font` instead (FontType is an old alias)") class FontType(Font): ... diff --git a/buildconfig/stubs/pygame/mask.pyi b/buildconfig/stubs/pygame/mask.pyi index 35763de6d7..0da8a2475f 100644 --- a/buildconfig/stubs/pygame/mask.pyi +++ b/buildconfig/stubs/pygame/mask.pyi @@ -55,5 +55,5 @@ class Mask: dest: Union[RectLike, Point] = (0, 0), ) -> Surface: ... -@deprecated("Use `Mask` instead (this is an old alias)") +@deprecated("Use `Mask` instead (MaskType is an old alias)") class MaskType(Mask): ... diff --git a/buildconfig/stubs/pygame/mixer.pyi b/buildconfig/stubs/pygame/mixer.pyi index 3bf929326f..198881789c 100644 --- a/buildconfig/stubs/pygame/mixer.pyi +++ b/buildconfig/stubs/pygame/mixer.pyi @@ -101,8 +101,8 @@ class Channel: def set_endevent(self, type: Union[int, Event] = 0, /) -> None: ... def get_endevent(self) -> int: ... -@deprecated("Use `Sound` instead (this is an old alias)") +@deprecated("Use `Sound` instead (SoundType is an old alias)") class SoundType(Sound): ... -@deprecated("Use `Channel` instead (this is an old alias)") +@deprecated("Use `Channel` instead (ChannelType is an old alias)") class ChannelType(Channel): ... diff --git a/buildconfig/stubs/pygame/rect.pyi b/buildconfig/stubs/pygame/rect.pyi index 9e0409e4c4..e8a49d5f31 100644 --- a/buildconfig/stubs/pygame/rect.pyi +++ b/buildconfig/stubs/pygame/rect.pyi @@ -277,8 +277,8 @@ class Rect(_GenericRect[int]): class FRect(_GenericRect[float]): ... -@deprecated("Use `Rect` instead (this is an old alias)") +@deprecated("Use `Rect` instead (RectType is an old alias)") class RectType(Rect): ... -@deprecated("Use `FRect` instead (this is an old alias)") +@deprecated("Use `FRect` instead (FRectType is an old alias)") class FRectType(FRect): ... diff --git a/buildconfig/stubs/pygame/surface.pyi b/buildconfig/stubs/pygame/surface.pyi index 030e27904b..b439d479e1 100644 --- a/buildconfig/stubs/pygame/surface.pyi +++ b/buildconfig/stubs/pygame/surface.pyi @@ -168,5 +168,5 @@ class Surface: def premul_alpha(self) -> Surface: ... def premul_alpha_ip(self) -> Surface: ... -@deprecated("Use `Surface` instead (this is an old alias)") +@deprecated("Use `Surface` instead (SurfaceType is an old alias)") class SurfaceType(Surface): ...