Skip to content

Commit d4c3eae

Browse files
authored
Mark old xType aliases as deprecated (#3288)
* 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. * Mark old types deprecated: don't duplicate event * Mark old types deprecated: clearer wording
1 parent b6d2987 commit d4c3eae

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

buildconfig/stubs/pygame/event.pyi

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from typing import Any, Optional, Union, final
2+
from typing_extensions import deprecated # added in 3.13
23

34
from pygame.typing import SequenceLike
45

5-
@final
6-
class Event:
6+
class _GenericEvent:
7+
# Just exists to avoid duplication of data for Event
8+
# and (deprecated) EventType
9+
710
@property
811
def type(self) -> int: ...
912
__dict__: dict[str, Any]
@@ -21,6 +24,15 @@ class Event:
2124
@property
2225
def dict(self) -> dict[str, Any]: ...
2326

27+
@final
28+
class Event(_GenericEvent):
29+
pass
30+
31+
@final
32+
@deprecated("Use `Event` instead (EventType is an old alias)")
33+
class EventType(_GenericEvent):
34+
pass
35+
2436
_EventTypes = Union[int, SequenceLike[int]]
2537

2638
def pump() -> None: ...
@@ -41,5 +53,3 @@ def set_grab(grab: bool, /) -> None: ...
4153
def get_grab() -> bool: ...
4254
def post(event: Event, /) -> bool: ...
4355
def custom_type() -> int: ...
44-
45-
EventType = Event

buildconfig/stubs/pygame/font.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections.abc import Callable, Hashable, Iterable
22
from typing import Literal, Optional, Union
3+
from typing_extensions import deprecated # added in 3.13
34

45
from pygame.surface import Surface
56

@@ -87,4 +88,5 @@ class Font:
8788
def get_point_size(self) -> int: ...
8889
def set_point_size(self, val: int, /) -> None: ...
8990

90-
FontType = Font
91+
@deprecated("Use `Font` instead (FontType is an old alias)")
92+
class FontType(Font): ...

buildconfig/stubs/pygame/mask.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, Optional, Union
2+
from typing_extensions import deprecated # added in 3.13
23

34
from pygame.rect import Rect
45
from pygame.surface import Surface
@@ -54,4 +55,5 @@ class Mask:
5455
dest: Union[RectLike, Point] = (0, 0),
5556
) -> Surface: ...
5657

57-
MaskType = Mask
58+
@deprecated("Use `Mask` instead (MaskType is an old alias)")
59+
class MaskType(Mask): ...

buildconfig/stubs/pygame/mixer.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any, Optional, Union, overload
2+
from typing_extensions import deprecated # added in 3.13
23

34
import numpy
45

@@ -100,5 +101,8 @@ class Channel:
100101
def set_endevent(self, type: Union[int, Event] = 0, /) -> None: ...
101102
def get_endevent(self) -> int: ...
102103

103-
SoundType = Sound
104-
ChannelType = Channel
104+
@deprecated("Use `Sound` instead (SoundType is an old alias)")
105+
class SoundType(Sound): ...
106+
107+
@deprecated("Use `Channel` instead (ChannelType is an old alias)")
108+
class ChannelType(Channel): ...

buildconfig/stubs/pygame/rect.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from typing import (
88
overload,
99
Optional,
1010
)
11+
from typing_extensions import deprecated # added in 3.13
1112

1213
from pygame.typing import Point, RectLike, SequenceLike
1314

@@ -285,5 +286,8 @@ class Rect(_GenericRect[int]):
285286
class FRect(_GenericRect[float]):
286287
...
287288

288-
RectType = Rect
289-
FRectType = FRect
289+
@deprecated("Use `Rect` instead (RectType is an old alias)")
290+
class RectType(Rect): ...
291+
292+
@deprecated("Use `FRect` instead (FRectType is an old alias)")
293+
class FRectType(FRect): ...

buildconfig/stubs/pygame/surface.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,5 @@ class Surface:
168168
def premul_alpha(self) -> Surface: ...
169169
def premul_alpha_ip(self) -> Surface: ...
170170

171-
SurfaceType = Surface
171+
@deprecated("Use `Surface` instead (SurfaceType is an old alias)")
172+
class SurfaceType(Surface): ...

0 commit comments

Comments
 (0)