Skip to content

Commit

Permalink
Merge pull request #3172 from aatle/improve-geometry-stub
Browse files Browse the repository at this point in the history
Minor fixes and changes to `geometry.pyi` stub file
  • Loading branch information
ankith26 authored Oct 17, 2024
2 parents e945551 + fea6cc7 commit 9218eb2
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions buildconfig/stubs/pygame/geometry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,26 @@ 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[
Line,
SequenceLike[float],
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[_CircleLike, Callable[[], _CircleLike]]: ...

_CircleValue = Union[_CanBeCircle, _HasCirclettribute]
_CircleLike = 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
line: Union[_CanBeLine, Callable[[], _CanBeLine]]

@property
def line(self) -> Union[_LineLike, Callable[[], _LineLike]]: ...

_LineValue = Union[_CanBeLine, _HasLineAttribute]
_LineLike = Union[Line, SequenceLike[float], SequenceLike[Point], _HasLineAttribute]

_CanBeCollided = Union[Circle, Rect, FRect, Point, Vector2]
_CanBeCollided = Union[Circle, Rect, FRect, Point]
_CanBeIntersected = Union[Circle]

class Circle:
Expand Down Expand Up @@ -99,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
Expand All @@ -113,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
Expand All @@ -128,9 +123,9 @@ 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: ...
def update(self, circle: _CircleLike, /) -> None: ...
@overload
def update(self, x: float, y: float, r: float, /) -> None: ...
@overload
Expand Down Expand Up @@ -178,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: ...

0 comments on commit 9218eb2

Please sign in to comment.