Improve turtle.Vec2D (#8058)

Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
Alex Waygood
2022-06-12 13:53:14 +01:00
committed by GitHub
parent a750a42c65
commit 16281bb04f

View File

@@ -142,9 +142,18 @@ _PenState: TypeAlias = dict[str, Any]
_Speed: TypeAlias = str | float
_PolygonCoords: TypeAlias = Sequence[tuple[float, float]]
# TODO: Type this more accurately
# Vec2D is actually a custom subclass of 'tuple'.
Vec2D: TypeAlias = tuple[float, float]
class Vec2D(tuple[float, float]):
def __new__(cls: type[Self], x: float, y: float) -> Self: ...
def __add__(self, other: tuple[float, float]) -> Vec2D: ... # type: ignore[override]
@overload # type: ignore[override]
def __mul__(self, other: Vec2D) -> float: ...
@overload
def __mul__(self, other: float) -> Vec2D: ...
def __rmul__(self, other: float) -> Vec2D: ... # type: ignore[override]
def __sub__(self, other: tuple[float, float]) -> Vec2D: ...
def __neg__(self) -> Vec2D: ...
def __abs__(self) -> float: ...
def rotate(self, angle: float) -> Vec2D: ...
# Does not actually inherit from Canvas, but dynamically gets all methods of Canvas
class ScrolledCanvas(Canvas, Frame): # type: ignore[misc]