From 227d1f5d49bd1ded76c62257413d76964477b676 Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Sun, 15 Sep 2024 21:33:44 -0700 Subject: [PATCH] Remove RGBATuple My contention is that we don't need a type alias for this, we should show what functions actually return instead of adding an additional level of indirection. It is the documentation's job to say how the returned values should be interpreted, not the type system's. --- buildconfig/stubs/pygame/surface.pyi | 3 +-- buildconfig/stubs/pygame/transform.pyi | 6 +++--- buildconfig/stubs/pygame/typing.pyi | 3 --- buildconfig/stubs/typing_sample_app.py | 5 ----- docs/reST/ref/typing.rst | 4 ---- src_c/doc/typing_doc.h | 1 - src_py/typing.py | 3 --- 7 files changed, 4 insertions(+), 21 deletions(-) diff --git a/buildconfig/stubs/pygame/surface.pyi b/buildconfig/stubs/pygame/surface.pyi index df6c2819ad..e9a97e070f 100644 --- a/buildconfig/stubs/pygame/surface.pyi +++ b/buildconfig/stubs/pygame/surface.pyi @@ -9,7 +9,6 @@ from pygame.typing import ( ColorLike, Coordinate, RectLike, - RGBATuple, SequenceLike, ) @@ -109,7 +108,7 @@ class Surface: def set_colorkey(self, color: ColorLike, flags: int = 0, /) -> None: ... @overload def set_colorkey(self, color: None, /) -> None: ... - def get_colorkey(self) -> Optional[RGBATuple]: ... + def get_colorkey(self) -> Optional[Tuple[int, int, int, int]]: ... @overload def set_alpha(self, value: int, flags: int = 0, /) -> None: ... @overload diff --git a/buildconfig/stubs/pygame/transform.pyi b/buildconfig/stubs/pygame/transform.pyi index 76c58c6dac..fa0709e394 100644 --- a/buildconfig/stubs/pygame/transform.pyi +++ b/buildconfig/stubs/pygame/transform.pyi @@ -1,8 +1,8 @@ -from typing import Optional, Union, Literal +from typing import Optional, Union, Literal, Tuple from pygame.surface import Surface -from pygame.typing import ColorLike, Coordinate, RectLike, SequenceLike, RGBATuple +from pygame.typing import ColorLike, Coordinate, RectLike, SequenceLike def flip(surface: Surface, flip_x: bool, flip_y: bool) -> Surface: ... def scale( @@ -41,7 +41,7 @@ def average_surfaces( ) -> Surface: ... def average_color( surface: Surface, rect: Optional[RectLike] = None, consider_alpha: bool = False -) -> RGBATuple: ... +) -> Tuple[int, int, int, int]: ... def threshold( dest_surface: Optional[Surface], surface: Surface, diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 2707a37557..852c5192fb 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -8,7 +8,6 @@ __all__ = [ "SequenceLike", "FileLike", "ColorLike", - "RGBATuple", "Coordinate", "IntCoordinate", ] @@ -54,8 +53,6 @@ Coordinate = SequenceLike[float] # This is used where ints are strictly required IntCoordinate = SequenceLike[int] -# Used for functions that return an RGBA tuple -RGBATuple = Tuple[int, int, int, int] ColorLike = Union[int, str, SequenceLike[int]] diff --git a/buildconfig/stubs/typing_sample_app.py b/buildconfig/stubs/typing_sample_app.py index 58e853cbc8..454f7702af 100644 --- a/buildconfig/stubs/typing_sample_app.py +++ b/buildconfig/stubs/typing_sample_app.py @@ -77,15 +77,10 @@ def validator_IntCoordinate(coordinate: typing.IntCoordinate) -> int: validator_IntCoordinate([-4, -3]) -# validate RGBATuple, ColorLike -def validator_RGBATuple(rgba: typing.RGBATuple) -> int: - return 0 - def validator_ColorLike(color: typing.ColorLike) -> int: return 0 # must pass -validator_RGBATuple((100, 200, 50, 20)) validator_ColorLike("green") validator_ColorLike(1) validator_ColorLike((255, 255, 255, 30)) diff --git a/docs/reST/ref/typing.rst b/docs/reST/ref/typing.rst index 7c71f6e18b..de79ecc76b 100644 --- a/docs/reST/ref/typing.rst +++ b/docs/reST/ref/typing.rst @@ -50,10 +50,6 @@ type aliases for proper typehint annotations. A sequence of strictly two integers such as ``[a, b]`` or ``(a, b)``. - .. data:: RGBATuple - - A tuple of four integers ``(r, g, b, a)`` in range 0-255 such as ``(20, 255, 0, 100)``. - .. data:: ColorLike An object representing a color such as a mapped integer, a string or diff --git a/src_c/doc/typing_doc.h b/src_c/doc/typing_doc.h index 28bc35fd91..ce82b28d18 100644 --- a/src_c/doc/typing_doc.h +++ b/src_c/doc/typing_doc.h @@ -4,6 +4,5 @@ #define DOC_TYPING_SEQUENCELIKE "" #define DOC_TYPING_COORDINATE "" #define DOC_TYPING_INTCOORDINATE "" -#define DOC_TYPING_RGBATUPLE "" #define DOC_TYPING_COLORLIKE "" #define DOC_TYPING_RECTLIKE "" diff --git a/src_py/typing.py b/src_py/typing.py index 2707a37557..852c5192fb 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -8,7 +8,6 @@ "SequenceLike", "FileLike", "ColorLike", - "RGBATuple", "Coordinate", "IntCoordinate", ] @@ -54,8 +53,6 @@ def __len__(self) -> int: ... # This is used where ints are strictly required IntCoordinate = SequenceLike[int] -# Used for functions that return an RGBA tuple -RGBATuple = Tuple[int, int, int, int] ColorLike = Union[int, str, SequenceLike[int]]