Skip to content

Commit 8b09b1f

Browse files
authored
Include the explicit type in ColorLike and RectLike (#3183)
* Include the explicit type in type unions * Sort ColorLike types by how common they are
1 parent 120675a commit 8b09b1f

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

buildconfig/stubs/pygame/typing.pyi

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import sys
1616
from abc import abstractmethod
1717
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
1818

19+
from pygame.color import Color
20+
from pygame.rect import Rect, FRect
21+
22+
1923
if sys.version_info >= (3, 9):
2024
from os import PathLike as _PathProtocol
2125
else:
@@ -53,7 +57,7 @@ Point = SequenceLike[float]
5357
# This is used where ints are strictly required
5458
IntPoint = SequenceLike[int]
5559

56-
ColorLike = Union[int, str, SequenceLike[int]]
60+
ColorLike = Union[Color, SequenceLike[int], str, int]
5761

5862

5963
class _HasRectAttribute(Protocol):
@@ -63,8 +67,22 @@ class _HasRectAttribute(Protocol):
6367
def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ...
6468

6569

66-
RectLike = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]
70+
RectLike = Union[
71+
Rect, FRect, SequenceLike[float], SequenceLike[Point], _HasRectAttribute
72+
]
6773

6874

6975
# cleanup namespace
70-
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
76+
del (
77+
sys,
78+
abstractmethod,
79+
Color,
80+
Rect,
81+
FRect,
82+
IO,
83+
Callable,
84+
Tuple,
85+
Union,
86+
TypeVar,
87+
Protocol,
88+
)

src_py/typing.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
from abc import abstractmethod
1717
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol
1818

19+
from pygame.color import Color
20+
from pygame.rect import Rect, FRect
21+
22+
1923
if sys.version_info >= (3, 9):
2024
from os import PathLike as _PathProtocol
2125
else:
@@ -53,7 +57,7 @@ def __len__(self) -> int: ...
5357
# This is used where ints are strictly required
5458
IntPoint = SequenceLike[int]
5559

56-
ColorLike = Union[int, str, SequenceLike[int]]
60+
ColorLike = Union[Color, SequenceLike[int], str, int]
5761

5862

5963
class _HasRectAttribute(Protocol):
@@ -63,8 +67,22 @@ class _HasRectAttribute(Protocol):
6367
def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ...
6468

6569

66-
RectLike = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]
70+
RectLike = Union[
71+
Rect, FRect, SequenceLike[float], SequenceLike[Point], _HasRectAttribute
72+
]
6773

6874

6975
# cleanup namespace
70-
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
76+
del (
77+
sys,
78+
abstractmethod,
79+
Color,
80+
Rect,
81+
FRect,
82+
IO,
83+
Callable,
84+
Tuple,
85+
Union,
86+
TypeVar,
87+
Protocol,
88+
)

0 commit comments

Comments
 (0)