From 098b452e1479d6e6764d96d10fc35de369e9688f Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Tue, 27 Jan 2026 23:18:10 -0500 Subject: [PATCH 1/2] Implement typing overloads for (matrix) multiplication --- src/affine.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/affine.py b/src/affine.py index 41c54ed..8f0ec4a 100644 --- a/src/affine.py +++ b/src/affine.py @@ -37,10 +37,14 @@ from collections.abc import MutableSequence, Sequence from functools import cached_property import math +from typing import TYPE_CHECKING import warnings from attrs import astuple, define, field +if TYPE_CHECKING: + from typing import overload + __all__ = ["Affine"] __author__ = "Sean Gillies" __version__ = "3.0rc2" @@ -550,6 +554,17 @@ def __add__(self, other): __iadd__ = __add__ + @overload + def __matmul__(self, other: Affine) -> Affine: ... + @overload + def __matmul__(self, other: tuple[float, float]) -> tuple[float, float]: ... + @overload + def __matmul__( + self, other: tuple[float, float, float] + ) -> tuple[float, float, float]: ... + # For other float sequences, we don't know the returned tuple length here + @overload + def __matmul__(self, other: Sequence[float]) -> tuple[float, ...]: ... def __matmul__(self, other): """Matrix multiplication. @@ -610,6 +625,10 @@ def __imatmul__(self, other): raise TypeError("Operation not supported") return NotImplemented + @overload + def __mul__(self, other: Affine) -> Affine: ... + @overload + def __mul__(self, other: tuple[float, float]) -> tuple[float, float]: ... def __mul__(self, other): """Multiplication. From 1de892881f66c6be659034be8a9c758779692eb5 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Wed, 28 Jan 2026 10:54:31 -0500 Subject: [PATCH 2/2] fix lints --- src/affine/__init__.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/affine/__init__.py b/src/affine/__init__.py index 8f0ec4a..ca7fe02 100644 --- a/src/affine/__init__.py +++ b/src/affine/__init__.py @@ -37,14 +37,11 @@ from collections.abc import MutableSequence, Sequence from functools import cached_property import math -from typing import TYPE_CHECKING +from typing import overload import warnings from attrs import astuple, define, field -if TYPE_CHECKING: - from typing import overload - __all__ = ["Affine"] __author__ = "Sean Gillies" __version__ = "3.0rc2" @@ -620,7 +617,7 @@ def __matmul__(self, other): def __rmatmul__(self, other): return NotImplemented - def __imatmul__(self, other): + def __imatmul__(self, other): # type: ignore if not isinstance(other, Affine): raise TypeError("Operation not supported") return NotImplemented @@ -661,7 +658,7 @@ def __mul__(self, other): def __rmul__(self, other): return NotImplemented - def __imul__(self, other): + def __imul__(self, other): # type: ignore if isinstance(other, tuple): warnings.warn( "in-place multiplication with tuple is deprecated",