Skip to content

Include the explicit type in ColorLike and RectLike #3183

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions buildconfig/stubs/pygame/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import sys
from abc import abstractmethod
from typing import IO, Callable, Tuple, 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:
Expand Down Expand Up @@ -53,7 +57,7 @@ Point = SequenceLike[float]
# This is used where ints are strictly required
IntPoint = SequenceLike[int]

ColorLike = Union[int, str, SequenceLike[int]]
ColorLike = Union[Color, SequenceLike[int], str, int]


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


RectLike = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]
RectLike = Union[
Rect, FRect, SequenceLike[float], SequenceLike[Point], _HasRectAttribute
]


# cleanup namespace
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
del (
sys,
abstractmethod,
Color,
Rect,
FRect,
IO,
Callable,
Tuple,
Union,
TypeVar,
Protocol,
)
24 changes: 21 additions & 3 deletions src_py/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from abc import abstractmethod
from typing import IO, Callable, Tuple, 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:
Expand Down Expand Up @@ -53,7 +57,7 @@ def __len__(self) -> int: ...
# This is used where ints are strictly required
IntPoint = SequenceLike[int]

ColorLike = Union[int, str, SequenceLike[int]]
ColorLike = Union[Color, SequenceLike[int], str, int]


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


RectLike = Union[SequenceLike[float], SequenceLike[Point], _HasRectAttribute]
RectLike = Union[
Rect, FRect, SequenceLike[float], SequenceLike[Point], _HasRectAttribute
]


# cleanup namespace
del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol
del (
sys,
abstractmethod,
Color,
Rect,
FRect,
IO,
Callable,
Tuple,
Union,
TypeVar,
Protocol,
)
Loading