From 293078cf4cf67d85241a24c4ee134bd232499126 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:10:38 -0700 Subject: [PATCH 1/6] Fix geometry has-attribute protocols --- buildconfig/stubs/pygame/geometry.pyi | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index d5230ef98c..5dac798409 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -19,17 +19,19 @@ _CanBeLine = Union[ SequenceLike[Point], ] -class _HasCirclettribute(Protocol): +class _HasCircleAttribute(Protocol): # An object that has a circle attribute that is either a circle, or a function # that returns a circle - circle: Union[_CanBeCircle, Callable[[], _CanBeCircle]] + @property + def circle(self) -> Union[_CanBeCircle, Callable[[], _CanBeCircle]]: ... -_CircleValue = Union[_CanBeCircle, _HasCirclettribute] +_CircleValue = Union[_CanBeCircle, _HasCircleAttribute] class _HasLineAttribute(Protocol): # An object that has a line attribute that is either a line, or a function # that returns a line - line: Union[_CanBeLine, Callable[[], _CanBeLine]] + @property + def line(self) -> Union[_CanBeLine, Callable[[], _CanBeLine]]: ... _LineValue = Union[_CanBeLine, _HasLineAttribute] From ed821b6c371e4fc79d9642532dd8fc5177a3de5d Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:11:24 -0700 Subject: [PATCH 2/6] Remove redundant type from type union --- buildconfig/stubs/pygame/geometry.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 5dac798409..dbcba946e8 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -10,7 +10,6 @@ from typing import ( from pygame import Rect, FRect from pygame.typing import Point, RectLike, SequenceLike -from .math import Vector2 _CanBeCircle = Union[Circle, Tuple[Point, float], SequenceLike[float]] _CanBeLine = Union[ @@ -36,7 +35,7 @@ class _HasLineAttribute(Protocol): _LineValue = Union[_CanBeLine, _HasLineAttribute] -_CanBeCollided = Union[Circle, Rect, FRect, Point, Vector2] +_CanBeCollided = Union[Circle, Rect, FRect, Point] _CanBeIntersected = Union[Circle] class Circle: From e1c2335ed8195838472c1464f9c5ec1ca3c2be5e Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:18:07 -0700 Subject: [PATCH 3/6] Type Circle.contains parameter as positional-only --- buildconfig/stubs/pygame/geometry.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index dbcba946e8..dc4e0985a6 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -129,7 +129,7 @@ class Circle: def collidelist(self, colliders: Sequence[_CanBeCollided], /) -> int: ... def collidelistall(self, colliders: Sequence[_CanBeCollided], /) -> List[int]: ... def intersect(self, other: _CanBeIntersected, /) -> List[Tuple[float, float]]: ... - def contains(self, shape: _CanBeCollided) -> bool: ... + def contains(self, shape: _CanBeCollided, /) -> bool: ... @overload def update(self, circle: _CircleValue, /) -> None: ... @overload From d735f3a67818c439c4f61dbba54c49153ed03d89 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:19:55 -0700 Subject: [PATCH 4/6] Format geometry.pyi --- buildconfig/stubs/pygame/geometry.pyi | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index dc4e0985a6..8b22de4788 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -12,11 +12,7 @@ from pygame import Rect, FRect from pygame.typing import Point, RectLike, SequenceLike _CanBeCircle = Union[Circle, Tuple[Point, float], SequenceLike[float]] -_CanBeLine = Union[ - Line, - SequenceLike[float], - SequenceLike[Point], -] +_CanBeLine = Union[Line, SequenceLike[float], SequenceLike[Point]] class _HasCircleAttribute(Protocol): # An object that has a circle attribute that is either a circle, or a function @@ -32,7 +28,6 @@ class _HasLineAttribute(Protocol): @property def line(self) -> Union[_CanBeLine, Callable[[], _CanBeLine]]: ... - _LineValue = Union[_CanBeLine, _HasLineAttribute] _CanBeCollided = Union[Circle, Rect, FRect, Point] From 06888230809cf0d510c93b18bdb0fef23694b81e Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:34:36 -0700 Subject: [PATCH 5/6] Combine geometry type unions --- buildconfig/stubs/pygame/geometry.pyi | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index 8b22de4788..d0ae492dd9 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -11,24 +11,23 @@ from typing import ( from pygame import Rect, FRect from pygame.typing import Point, RectLike, SequenceLike -_CanBeCircle = Union[Circle, Tuple[Point, float], SequenceLike[float]] -_CanBeLine = Union[Line, SequenceLike[float], SequenceLike[Point]] - class _HasCircleAttribute(Protocol): # An object that has a circle attribute that is either a circle, or a function # that returns a circle @property - def circle(self) -> Union[_CanBeCircle, Callable[[], _CanBeCircle]]: ... + def circle(self) -> Union[_CircleValue, Callable[[], _CircleValue]]: ... -_CircleValue = Union[_CanBeCircle, _HasCircleAttribute] +_CircleValue = Union[ + Circle, Tuple[Point, float], SequenceLike[float], _HasCircleAttribute +] class _HasLineAttribute(Protocol): # An object that has a line attribute that is either a line, or a function # that returns a line @property - def line(self) -> Union[_CanBeLine, Callable[[], _CanBeLine]]: ... + def line(self) -> Union[_LineValue, Callable[[], _LineValue]]: ... -_LineValue = Union[_CanBeLine, _HasLineAttribute] +_LineValue = Union[Line, SequenceLike[float], SequenceLike[Point], _HasLineAttribute] _CanBeCollided = Union[Circle, Rect, FRect, Point] _CanBeIntersected = Union[Circle] From fea6cc7cdd3b96aef07d5a7ca96765717ebf4623 Mon Sep 17 00:00:00 2001 From: aatle <168398276+aatle@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:35:58 -0700 Subject: [PATCH 6/6] Rename internal geometry type unions --- buildconfig/stubs/pygame/geometry.pyi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index d0ae492dd9..f7c1edf517 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -15,9 +15,9 @@ class _HasCircleAttribute(Protocol): # An object that has a circle attribute that is either a circle, or a function # that returns a circle @property - def circle(self) -> Union[_CircleValue, Callable[[], _CircleValue]]: ... + def circle(self) -> Union[_CircleLike, Callable[[], _CircleLike]]: ... -_CircleValue = Union[ +_CircleLike = Union[ Circle, Tuple[Point, float], SequenceLike[float], _HasCircleAttribute ] @@ -25,9 +25,9 @@ class _HasLineAttribute(Protocol): # An object that has a line attribute that is either a line, or a function # that returns a line @property - def line(self) -> Union[_LineValue, Callable[[], _LineValue]]: ... + def line(self) -> Union[_LineLike, Callable[[], _LineLike]]: ... -_LineValue = Union[Line, SequenceLike[float], SequenceLike[Point], _HasLineAttribute] +_LineLike = Union[Line, SequenceLike[float], SequenceLike[Point], _HasLineAttribute] _CanBeCollided = Union[Circle, Rect, FRect, Point] _CanBeIntersected = Union[Circle] @@ -94,7 +94,7 @@ class Circle: @overload def __init__(self, pos: Point, r: float) -> None: ... @overload - def __init__(self, circle: _CircleValue) -> None: ... + def __init__(self, circle: _CircleLike) -> None: ... @overload def move(self, x: float, y: float, /) -> Circle: ... @overload @@ -108,7 +108,7 @@ class Circle: @overload def collidepoint(self, point: Point, /) -> bool: ... @overload - def collidecircle(self, circle: _CircleValue, /) -> bool: ... + def collidecircle(self, circle: _CircleLike, /) -> bool: ... @overload def collidecircle(self, x: float, y: float, r: float, /) -> bool: ... @overload @@ -125,7 +125,7 @@ class Circle: def intersect(self, other: _CanBeIntersected, /) -> List[Tuple[float, float]]: ... def contains(self, shape: _CanBeCollided, /) -> bool: ... @overload - def update(self, circle: _CircleValue, /) -> None: ... + def update(self, circle: _CircleLike, /) -> None: ... @overload def update(self, x: float, y: float, r: float, /) -> None: ... @overload @@ -173,6 +173,6 @@ class Line: @overload def __init__(self, a: Point, b: Point) -> None: ... @overload - def __init__(self, line: _LineValue) -> None: ... + def __init__(self, line: _LineLike) -> None: ... def __copy__(self) -> Line: ... def copy(self) -> Line: ...