From 9436621abc86b48f025704fe5e629fb24749e1ae Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:02:15 -0700 Subject: [PATCH 01/16] Make _CanBeRect stricter --- src_py/typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_py/typing.py b/src_py/typing.py index 883fe2def1..e10d3c35a5 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -44,7 +44,7 @@ def __len__(self) -> int: ... RGBATuple = Tuple[int, int, int, int] ColorLike = Union[int, str, SequenceLike[int]] -_CanBeRect = SequenceLike[Union[float, Coordinate]] +_CanBeRect = Union[SequenceLike[float], SequenceLike[Coordinate]] class _HasRectAttribute(Protocol): From b18604fde04af0bbd9dc1898ec594f049c8c7c88 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:09:53 -0700 Subject: [PATCH 02/16] Fix type var of _PathProtocol --- src_py/typing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src_py/typing.py b/src_py/typing.py index e10d3c35a5..74c85cb8eb 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -9,10 +9,10 @@ if sys.version_info >= (3, 9): from os import PathLike as _PathProtocol else: - _T = TypeVar("_T", bound=Union[str, bytes]) + _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) - class _PathProtocol(Protocol[_T]): - def __fspath__(self) -> _T: ... + class _PathProtocol(Protocol[_AnyStr_co]): + def __fspath__(self) -> _AnyStr_co: ... # For functions that take a file name From d7ae971a57de5f1a8f134cacce69ef0573e2b1fe Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:19:09 -0700 Subject: [PATCH 03/16] Add more typing test cases --- buildconfig/stubs/typing_sample_app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/buildconfig/stubs/typing_sample_app.py b/buildconfig/stubs/typing_sample_app.py index dae94bd0ac..720db1ece4 100644 --- a/buildconfig/stubs/typing_sample_app.py +++ b/buildconfig/stubs/typing_sample_app.py @@ -97,13 +97,19 @@ def __init__(self): class MyObject2: def __init__(self): self.rect = lambda: pygame.Rect(5, 5, 10, 10) - + +class MyObject3: + def rect(self) -> pygame.Rect: + return pygame.Rect(15, 15, 30, 30) + def validator_RectLike(rect: typing.RectLike) -> int: return 0 # must pass validator_RectLike((10, 10, 10, 10)) validator_RectLike(((5, 5), (30, 30))) +validator_RectLike([(3, 3.2), pygame.Vector2()]) validator_RectLike(pygame.Rect(1, 2, 3, 4)) validator_RectLike(MyObject1()) validator_RectLike(MyObject2()) +validator_RectLike(MyObject3()) From 7961b95e7b214327a142f0eea0aae10531c4f322 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:33:20 -0700 Subject: [PATCH 04/16] Format typing_sample_app.py --- buildconfig/stubs/typing_sample_app.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/buildconfig/stubs/typing_sample_app.py b/buildconfig/stubs/typing_sample_app.py index 720db1ece4..dcb90c219a 100644 --- a/buildconfig/stubs/typing_sample_app.py +++ b/buildconfig/stubs/typing_sample_app.py @@ -1,10 +1,10 @@ -""" -Sample app run by mypy to ensure typing.py aliases work as expected -""" +"""Sample app run by mypy to ensure typing.py aliases work as expected""" + from pygame import typing import pygame import pathlib + # validate SequenceLike class MySequence: def __getitem__(self, index): @@ -13,10 +13,10 @@ def __getitem__(self, index): if index % 2 == 0: return 1 return 0 - + def __len__(self): return 20 - + def validator_SequenceLike(sequence: typing.SequenceLike) -> int: return 0 @@ -40,14 +40,15 @@ def validator_SequenceLikeTypes( (-1.5, -0.5, 0, 0.5, 2.5, 10), (-2, -1, 0, 1, 2, 3), "abcdefghijklmnopqrstuvwxyz", - [(0.5, 1.5), (-1, 1), "123", [(), (), ()]] + [(0.5, 1.5), (-1, 1), "123", [(), (), ()]], ) + # validate PathLike class MyPath: def __fspath__(self) -> str: return "file.py" - + def validator_PathLike(path: typing.PathLike) -> int: return 0 @@ -57,8 +58,8 @@ def validator_PathLike(path: typing.PathLike) -> int: validator_PathLike(pathlib.Path("file.py")) validator_PathLike(MyPath()) -# validate Coordinate, IntCoordinate +# validate Coordinate, IntCoordinate def validator_Coordinate(coordinate: typing.Coordinate) -> int: return 0 @@ -75,6 +76,7 @@ def validator_IntCoordinate(coordinate: typing.IntCoordinate) -> int: validator_IntCoordinate((3, 4)) validator_IntCoordinate([-4, -3]) + # validate RGBATuple, ColorLike def validator_RGBATuple(rgba: typing.RGBATuple) -> int: return 0 @@ -89,11 +91,12 @@ def validator_ColorLike(color: typing.ColorLike) -> int: validator_ColorLike((255, 255, 255, 30)) validator_ColorLike(pygame.Color(100, 100, 100, 100)) + # validate RectLike class MyObject1: def __init__(self): self.rect = pygame.Rect(10, 10, 20, 20) - + class MyObject2: def __init__(self): self.rect = lambda: pygame.Rect(5, 5, 10, 10) From cced2e89f2cff8b005a130fb04305e73ea3abf2d Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:41:47 -0700 Subject: [PATCH 05/16] Change index type to int in SequenceLike --- src_py/typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_py/typing.py b/src_py/typing.py index 74c85cb8eb..fe7fbc5ff9 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -28,7 +28,7 @@ class SequenceLike(Protocol[_T_co]): Variant of the standard `Sequence` ABC that only requires `__getitem__` and `__len__`. """ - def __getitem__(self, __i: SupportsIndex) -> _T_co: ... + def __getitem__(self, index: int, /) -> _T_co: ... def __len__(self) -> int: ... From 7ce777f2a3d62d0766327a77880b5d647dbcb408 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:44:20 -0700 Subject: [PATCH 06/16] Change _HasRectAttribute attr to non-writeable --- src_py/typing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src_py/typing.py b/src_py/typing.py index fe7fbc5ff9..cbdfcb439a 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -50,7 +50,8 @@ def __len__(self) -> int: ... class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function # that returns a rect conforms to the rect protocol - rect: Union["RectLike", Callable[[], "RectLike"]] + @property + def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... RectLike = Union[_CanBeRect, _HasRectAttribute] From c053b7de89c5121f88963ea5915e653b95ba663c Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:56:53 -0700 Subject: [PATCH 07/16] Use abstractmethod on pygame.typing protocols --- src_py/typing.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src_py/typing.py b/src_py/typing.py index cbdfcb439a..7302d011d0 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -4,6 +4,7 @@ # Use the command `python buildconfig/stubs/gen_stubs.py` to copy typing.py to typing.pyi import sys +from abc import abstractmethod from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex if sys.version_info >= (3, 9): @@ -28,7 +29,9 @@ class SequenceLike(Protocol[_T_co]): Variant of the standard `Sequence` ABC that only requires `__getitem__` and `__len__`. """ + @abstractmethod def __getitem__(self, index: int, /) -> _T_co: ... + @abstractmethod def __len__(self) -> int: ... @@ -51,6 +54,7 @@ class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function # that returns a rect conforms to the rect protocol @property + @abstractmethod def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... From 53ea6cc241e0dbaffe6f332e9d079eb96325fe57 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:00:08 -0700 Subject: [PATCH 08/16] Type annotate MySequence in typing_sample_app.py --- buildconfig/stubs/typing_sample_app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buildconfig/stubs/typing_sample_app.py b/buildconfig/stubs/typing_sample_app.py index dcb90c219a..a27ea6020f 100644 --- a/buildconfig/stubs/typing_sample_app.py +++ b/buildconfig/stubs/typing_sample_app.py @@ -7,14 +7,14 @@ # validate SequenceLike class MySequence: - def __getitem__(self, index): + def __getitem__(self, index: int) -> str: if index > 20: raise IndexError() if index % 2 == 0: - return 1 - return 0 + return "a" + return "bc" - def __len__(self): + def __len__(self) -> int: return 20 def validator_SequenceLike(sequence: typing.SequenceLike) -> int: From bf4c5a6b08987ab17cec536f54a7948b59c50cd2 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:04:29 -0700 Subject: [PATCH 09/16] Copy typing.py to stub typing.pyi --- buildconfig/stubs/pygame/typing.pyi | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 883fe2def1..7302d011d0 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -4,15 +4,16 @@ # Use the command `python buildconfig/stubs/gen_stubs.py` to copy typing.py to typing.pyi import sys +from abc import abstractmethod from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex if sys.version_info >= (3, 9): from os import PathLike as _PathProtocol else: - _T = TypeVar("_T", bound=Union[str, bytes]) + _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) - class _PathProtocol(Protocol[_T]): - def __fspath__(self) -> _T: ... + class _PathProtocol(Protocol[_AnyStr_co]): + def __fspath__(self) -> _AnyStr_co: ... # For functions that take a file name @@ -28,7 +29,9 @@ class SequenceLike(Protocol[_T_co]): Variant of the standard `Sequence` ABC that only requires `__getitem__` and `__len__`. """ - def __getitem__(self, __i: SupportsIndex) -> _T_co: ... + @abstractmethod + def __getitem__(self, index: int, /) -> _T_co: ... + @abstractmethod def __len__(self) -> int: ... @@ -44,13 +47,15 @@ IntCoordinate = SequenceLike[int] RGBATuple = Tuple[int, int, int, int] ColorLike = Union[int, str, SequenceLike[int]] -_CanBeRect = SequenceLike[Union[float, Coordinate]] +_CanBeRect = Union[SequenceLike[float], SequenceLike[Coordinate]] class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function # that returns a rect conforms to the rect protocol - rect: Union["RectLike", Callable[[], "RectLike"]] + @property + @abstractmethod + def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... RectLike = Union[_CanBeRect, _HasRectAttribute] From 8a5fa439e62dcbde58e445804146a415c93568f1 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:01:21 -0700 Subject: [PATCH 10/16] Fix faulty typing test case --- buildconfig/stubs/typing_sample_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildconfig/stubs/typing_sample_app.py b/buildconfig/stubs/typing_sample_app.py index a27ea6020f..33b3bac0a8 100644 --- a/buildconfig/stubs/typing_sample_app.py +++ b/buildconfig/stubs/typing_sample_app.py @@ -111,7 +111,7 @@ def validator_RectLike(rect: typing.RectLike) -> int: # must pass validator_RectLike((10, 10, 10, 10)) validator_RectLike(((5, 5), (30, 30))) -validator_RectLike([(3, 3.2), pygame.Vector2()]) +validator_RectLike(([3, 3.2], pygame.Vector2())) validator_RectLike(pygame.Rect(1, 2, 3, 4)) validator_RectLike(MyObject1()) validator_RectLike(MyObject2()) From 0052d97788744c81852e0e7b098c8d1cd448fbae Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:40:11 -0700 Subject: [PATCH 11/16] Create __all__ list for typing module --- buildconfig/stubs/pygame/typing.pyi | 11 +++++++++++ src_py/typing.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 7302d011d0..d56e17f82e 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -3,6 +3,17 @@ # NOTE: `src_py/typing.py` and `buildconfig/stubs/pygame/typing.pyi` must be duplicates. # Use the command `python buildconfig/stubs/gen_stubs.py` to copy typing.py to typing.pyi +__all__ = [ + "RectLike", + "SequenceLike", + "FileLike", + "PathLike", + "ColorLike", + "RGBATuple", + "Coordinate", + "IntCoordinate", +] + import sys from abc import abstractmethod from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex diff --git a/src_py/typing.py b/src_py/typing.py index 7302d011d0..d56e17f82e 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -3,6 +3,17 @@ # NOTE: `src_py/typing.py` and `buildconfig/stubs/pygame/typing.pyi` must be duplicates. # Use the command `python buildconfig/stubs/gen_stubs.py` to copy typing.py to typing.pyi +__all__ = [ + "RectLike", + "SequenceLike", + "FileLike", + "PathLike", + "ColorLike", + "RGBATuple", + "Coordinate", + "IntCoordinate", +] + import sys from abc import abstractmethod from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex From 4c8b1f07fb12c96a5c4f5359c7734b941df14791 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:58:40 -0700 Subject: [PATCH 12/16] Add another abstractmethod, remove SupportsIndex in typing --- buildconfig/stubs/pygame/typing.pyi | 5 +++-- src_py/typing.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index d56e17f82e..141e29da90 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -16,7 +16,7 @@ __all__ = [ import sys from abc import abstractmethod -from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex +from typing import IO, Callable, Tuple, Union, TypeVar, Protocol if sys.version_info >= (3, 9): from os import PathLike as _PathProtocol @@ -24,6 +24,7 @@ else: _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) class _PathProtocol(Protocol[_AnyStr_co]): + @abstractmethod def __fspath__(self) -> _AnyStr_co: ... @@ -72,4 +73,4 @@ class _HasRectAttribute(Protocol): RectLike = Union[_CanBeRect, _HasRectAttribute] # cleanup namespace -del sys, IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex +del sys, IO, Callable, Tuple, Union, TypeVar, Protocol diff --git a/src_py/typing.py b/src_py/typing.py index d56e17f82e..141e29da90 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -16,7 +16,7 @@ import sys from abc import abstractmethod -from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex +from typing import IO, Callable, Tuple, Union, TypeVar, Protocol if sys.version_info >= (3, 9): from os import PathLike as _PathProtocol @@ -24,6 +24,7 @@ _AnyStr_co = TypeVar("_AnyStr_co", str, bytes, covariant=True) class _PathProtocol(Protocol[_AnyStr_co]): + @abstractmethod def __fspath__(self) -> _AnyStr_co: ... @@ -72,4 +73,4 @@ def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... RectLike = Union[_CanBeRect, _HasRectAttribute] # cleanup namespace -del sys, IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex +del sys, IO, Callable, Tuple, Union, TypeVar, Protocol From c0761a149b487d88e7bb5394444c477140dedc28 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:20:39 -0700 Subject: [PATCH 13/16] Remove internal _CanBeRect type --- buildconfig/stubs/pygame/typing.pyi | 4 +--- src_py/typing.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 141e29da90..7174183b8c 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -59,8 +59,6 @@ IntCoordinate = SequenceLike[int] RGBATuple = Tuple[int, int, int, int] ColorLike = Union[int, str, SequenceLike[int]] -_CanBeRect = Union[SequenceLike[float], SequenceLike[Coordinate]] - class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function @@ -70,7 +68,7 @@ class _HasRectAttribute(Protocol): def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... -RectLike = Union[_CanBeRect, _HasRectAttribute] +RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute] # cleanup namespace del sys, IO, Callable, Tuple, Union, TypeVar, Protocol diff --git a/src_py/typing.py b/src_py/typing.py index 141e29da90..7174183b8c 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -59,8 +59,6 @@ def __len__(self) -> int: ... RGBATuple = Tuple[int, int, int, int] ColorLike = Union[int, str, SequenceLike[int]] -_CanBeRect = Union[SequenceLike[float], SequenceLike[Coordinate]] - class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function @@ -70,7 +68,7 @@ class _HasRectAttribute(Protocol): def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... -RectLike = Union[_CanBeRect, _HasRectAttribute] +RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute] # cleanup namespace del sys, IO, Callable, Tuple, Union, TypeVar, Protocol From 923cadcd2ac6c0aba5140248c0711b2c1edc7cde Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sun, 25 Aug 2024 13:55:19 -0700 Subject: [PATCH 14/16] Remove abstractmethod from rect protocol property --- buildconfig/stubs/pygame/typing.pyi | 5 +++-- src_py/typing.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 7174183b8c..704ce20958 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -64,11 +64,12 @@ class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function # that returns a rect conforms to the rect protocol @property - @abstractmethod - def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... + def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: + raise NotImplementedError RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute] + # cleanup namespace del sys, IO, Callable, Tuple, Union, TypeVar, Protocol diff --git a/src_py/typing.py b/src_py/typing.py index 7174183b8c..704ce20958 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -64,11 +64,12 @@ class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function # that returns a rect conforms to the rect protocol @property - @abstractmethod - def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... + def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: + raise NotImplementedError RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute] + # cleanup namespace del sys, IO, Callable, Tuple, Union, TypeVar, Protocol From 64267dd402a27adcf5bc289bb8cfc4eedb1d709c Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sun, 25 Aug 2024 15:00:38 -0700 Subject: [PATCH 15/16] Del abstractmethod at end of typing module --- buildconfig/stubs/pygame/typing.pyi | 2 +- src_py/typing.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 704ce20958..0abba66018 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -72,4 +72,4 @@ RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribut # cleanup namespace -del sys, IO, Callable, Tuple, Union, TypeVar, Protocol +del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol diff --git a/src_py/typing.py b/src_py/typing.py index 704ce20958..0abba66018 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -72,4 +72,4 @@ def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: # cleanup namespace -del sys, IO, Callable, Tuple, Union, TypeVar, Protocol +del sys, abstractmethod, IO, Callable, Tuple, Union, TypeVar, Protocol From d2c254f2e82dbd1a96d2d33bdd82c6f4d21bae45 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:31:53 -0700 Subject: [PATCH 16/16] Replace raise error with empty body in _HasRectAttribute --- buildconfig/stubs/pygame/typing.pyi | 3 +-- src_py/typing.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/buildconfig/stubs/pygame/typing.pyi b/buildconfig/stubs/pygame/typing.pyi index 0abba66018..f3f7aad434 100644 --- a/buildconfig/stubs/pygame/typing.pyi +++ b/buildconfig/stubs/pygame/typing.pyi @@ -64,8 +64,7 @@ class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function # that returns a rect conforms to the rect protocol @property - def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: - raise NotImplementedError + def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute] diff --git a/src_py/typing.py b/src_py/typing.py index 0abba66018..f3f7aad434 100644 --- a/src_py/typing.py +++ b/src_py/typing.py @@ -64,8 +64,7 @@ class _HasRectAttribute(Protocol): # An object that has a rect attribute that is either a rect, or a function # that returns a rect conforms to the rect protocol @property - def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: - raise NotImplementedError + def rect(self) -> Union["RectLike", Callable[[], "RectLike"]]: ... RectLike = Union[SequenceLike[float], SequenceLike[Coordinate], _HasRectAttribute]