From d4a81412ba6c416b3534c4f6cda0b608087f1d08 Mon Sep 17 00:00:00 2001 From: Damiano <97639432+damusss@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:48:18 +0200 Subject: [PATCH 1/2] Invert copy and __copy__ --- buildconfig/stubs/pygame/cursors.pyi | 4 ++-- buildconfig/stubs/pygame/geometry.pyi | 4 ++-- buildconfig/stubs/pygame/mask.pyi | 4 ++-- buildconfig/stubs/pygame/math.pyi | 4 ++-- buildconfig/stubs/pygame/rect.pyi | 4 ++-- buildconfig/stubs/pygame/surface.pyi | 4 ++-- src_py/cursors.py | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/buildconfig/stubs/pygame/cursors.pyi b/buildconfig/stubs/pygame/cursors.pyi index d75a66cc77..02a740e3fe 100644 --- a/buildconfig/stubs/pygame/cursors.pyi +++ b/buildconfig/stubs/pygame/cursors.pyi @@ -77,12 +77,12 @@ class Cursor: ) -> None: ... def __iter__(self) -> Iterator[Any]: ... def __len__(self) -> int: ... - def __copy__(self) -> Cursor: ... def __hash__(self) -> int: ... def __getitem__( self, index: int ) -> Union[int, IntCoordinate, Surface]: ... - copy = __copy__ + def copy(self) -> Cursor: ... + __copy__ = copy type: Literal["system", "color", "bitmap"] data: Union[ Tuple[int], diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 14ab6563b0..5c8e90f8a7 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -113,5 +113,5 @@ class Circle: def rotate_ip(self, angle: float, /) -> None: ... def as_rect(self) -> Rect: ... def as_frect(self) -> FRect: ... - def __copy__(self) -> Circle: ... - copy = __copy__ + def copy(self) -> Circle: ... + __copy__ = copy diff --git a/buildconfig/stubs/pygame/mask.pyi b/buildconfig/stubs/pygame/mask.pyi index 0ea50adeb6..30b6a9921b 100644 --- a/buildconfig/stubs/pygame/mask.pyi +++ b/buildconfig/stubs/pygame/mask.pyi @@ -16,8 +16,8 @@ def from_threshold( class Mask: def __init__(self, size: Coordinate, fill: bool = False) -> None: ... - def __copy__(self) -> Mask: ... - copy = __copy__ + def copy(self) -> Mask: ... + __copy__ = copy def get_size(self) -> Tuple[int, int]: ... def get_rect(self, **kwargs: Any) -> Rect: ... # Dict type needs to be completed def get_at(self, pos: Coordinate) -> int: ... diff --git a/buildconfig/stubs/pygame/math.pyi b/buildconfig/stubs/pygame/math.pyi index b994bcdab4..4920a77a8a 100644 --- a/buildconfig/stubs/pygame/math.pyi +++ b/buildconfig/stubs/pygame/math.pyi @@ -64,8 +64,8 @@ class _GenericVector(Collection[float]): def __imul__(self: _TVec, other: Union[SequenceLike[float], _TVec]) -> float: ... @overload def __imul__(self: _TVec, other: float) -> _TVec: ... - def __copy__(self: _TVec) -> _TVec: ... - copy = __copy__ + def copy(self: _TVec) -> _TVec: ... + __copy__ = copy def __safe_for_unpickling__(self) -> Literal[True]: ... def __contains__(self, other: float) -> bool: ... # type: ignore[override] def dot(self: _TVec, other: Union[SequenceLike[float], _TVec], /) -> float: ... diff --git a/buildconfig/stubs/pygame/rect.pyi b/buildconfig/stubs/pygame/rect.pyi index 79acedeab9..2d545aaef1 100644 --- a/buildconfig/stubs/pygame/rect.pyi +++ b/buildconfig/stubs/pygame/rect.pyi @@ -142,8 +142,8 @@ class _GenericRect(Collection[_N]): def __setitem__(self, key: int, value: float) -> None: ... @overload def __setitem__(self, key: slice, value: Union[float, RectLike]) -> None: ... - def __copy__(self) -> Self: ... - copy = __copy__ + def copy(self) -> Self: ... + __copy__ = copy @overload def move(self, x: float, y: float, /) -> Self: ... @overload diff --git a/buildconfig/stubs/pygame/surface.pyi b/buildconfig/stubs/pygame/surface.pyi index e9a97e070f..bb533f61dc 100644 --- a/buildconfig/stubs/pygame/surface.pyi +++ b/buildconfig/stubs/pygame/surface.pyi @@ -62,9 +62,9 @@ class Surface: flags: int = 0, surface: Surface = ..., ) -> None: ... - def __copy__(self) -> Surface: ... def __deepcopy__(self, memo) -> Surface: ... - copy = __copy__ + def copy(self) -> Surface: ... + __copy__ = copy def blit( self, source: Surface, diff --git a/src_py/cursors.py b/src_py/cursors.py index 7fa7f99315..342bce0313 100644 --- a/src_py/cursors.py +++ b/src_py/cursors.py @@ -106,12 +106,12 @@ def __eq__(self, other): def __ne__(self, other): return not self.__eq__(other) - def __copy__(self): + def copy(self): """Clone the current Cursor object. You can do the same thing by doing Cursor(Cursor).""" return self.__class__(self) - copy = __copy__ + __copy__ = copy def __hash__(self): return hash(tuple([self.type] + list(self.data))) From f4559474befc0a05ff05ea456a53e7be72b1b383 Mon Sep 17 00:00:00 2001 From: Damiano <97639432+damusss@users.noreply.github.com> Date: Sun, 29 Sep 2024 16:24:12 +0200 Subject: [PATCH 2/2] Replace inversion with explicitness --- buildconfig/stubs/pygame/cursors.pyi | 2 +- buildconfig/stubs/pygame/geometry.pyi | 2 +- buildconfig/stubs/pygame/mask.pyi | 2 +- buildconfig/stubs/pygame/math.pyi | 2 +- buildconfig/stubs/pygame/rect.pyi | 2 +- buildconfig/stubs/pygame/surface.pyi | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/buildconfig/stubs/pygame/cursors.pyi b/buildconfig/stubs/pygame/cursors.pyi index 02a740e3fe..0bd2d77c6d 100644 --- a/buildconfig/stubs/pygame/cursors.pyi +++ b/buildconfig/stubs/pygame/cursors.pyi @@ -77,12 +77,12 @@ class Cursor: ) -> None: ... def __iter__(self) -> Iterator[Any]: ... def __len__(self) -> int: ... + def __copy__(self) -> Cursor: ... def __hash__(self) -> int: ... def __getitem__( self, index: int ) -> Union[int, IntCoordinate, Surface]: ... def copy(self) -> Cursor: ... - __copy__ = copy type: Literal["system", "color", "bitmap"] data: Union[ Tuple[int], diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 5c8e90f8a7..135b806cc8 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -114,4 +114,4 @@ class Circle: def as_rect(self) -> Rect: ... def as_frect(self) -> FRect: ... def copy(self) -> Circle: ... - __copy__ = copy + def __copy__(self) -> Circle: ... diff --git a/buildconfig/stubs/pygame/mask.pyi b/buildconfig/stubs/pygame/mask.pyi index 30b6a9921b..667bc7f7b7 100644 --- a/buildconfig/stubs/pygame/mask.pyi +++ b/buildconfig/stubs/pygame/mask.pyi @@ -16,8 +16,8 @@ def from_threshold( class Mask: def __init__(self, size: Coordinate, fill: bool = False) -> None: ... + def __copy__(self) -> Mask: ... def copy(self) -> Mask: ... - __copy__ = copy def get_size(self) -> Tuple[int, int]: ... def get_rect(self, **kwargs: Any) -> Rect: ... # Dict type needs to be completed def get_at(self, pos: Coordinate) -> int: ... diff --git a/buildconfig/stubs/pygame/math.pyi b/buildconfig/stubs/pygame/math.pyi index 4920a77a8a..4526960b5a 100644 --- a/buildconfig/stubs/pygame/math.pyi +++ b/buildconfig/stubs/pygame/math.pyi @@ -64,8 +64,8 @@ class _GenericVector(Collection[float]): def __imul__(self: _TVec, other: Union[SequenceLike[float], _TVec]) -> float: ... @overload def __imul__(self: _TVec, other: float) -> _TVec: ... + def __copy__(self: _TVec) -> _TVec: ... def copy(self: _TVec) -> _TVec: ... - __copy__ = copy def __safe_for_unpickling__(self) -> Literal[True]: ... def __contains__(self, other: float) -> bool: ... # type: ignore[override] def dot(self: _TVec, other: Union[SequenceLike[float], _TVec], /) -> float: ... diff --git a/buildconfig/stubs/pygame/rect.pyi b/buildconfig/stubs/pygame/rect.pyi index 2d545aaef1..6e55ce45d7 100644 --- a/buildconfig/stubs/pygame/rect.pyi +++ b/buildconfig/stubs/pygame/rect.pyi @@ -142,8 +142,8 @@ class _GenericRect(Collection[_N]): def __setitem__(self, key: int, value: float) -> None: ... @overload def __setitem__(self, key: slice, value: Union[float, RectLike]) -> None: ... + def __copy__(self) -> Self: ... def copy(self) -> Self: ... - __copy__ = copy @overload def move(self, x: float, y: float, /) -> Self: ... @overload diff --git a/buildconfig/stubs/pygame/surface.pyi b/buildconfig/stubs/pygame/surface.pyi index bb533f61dc..697944313c 100644 --- a/buildconfig/stubs/pygame/surface.pyi +++ b/buildconfig/stubs/pygame/surface.pyi @@ -62,9 +62,9 @@ class Surface: flags: int = 0, surface: Surface = ..., ) -> None: ... + def __copy__(self) -> Surface: ... def __deepcopy__(self, memo) -> Surface: ... def copy(self) -> Surface: ... - __copy__ = copy def blit( self, source: Surface,