-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete type hints #121
Complete type hints #121
Conversation
Resolves #74
`a`, `b`, and `c` are the elements of the first row of the | ||
matrix. `d`, `e`, and `f` are the elements of the second row. | ||
Coefficients of the 3 x 3 augmented affine transformation | ||
matrix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to type hinting: I removed a duplicated diagram.
src/affine.py
Outdated
def from_gdal(cls, c: float, a: float, b: float, f: float, d: float, e: float): | ||
def from_gdal( | ||
cls, c: float, a: float, b: float, f: float, d: float, e: float | ||
) -> "Affine": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy was fine with Affine
, but ruff insists on quotes 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a typing pro, but after a 20 second read of PEP 649 it is potentially related. Add from __future__ import annotations
to the top which should make ruff happy.
src/affine.py
Outdated
@@ -281,7 +280,7 @@ def permutation(cls, *scaling): | |||
""" | |||
return cls(0.0, 1.0, 0.0, 1.0, 0.0, 0.0) | |||
|
|||
def __array__(self, dtype=None, copy=None): | |||
def __array__(self, dtype=None, copy: Optional[bool] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm skipping the type hint for dtype, to avoid a dependency on numpy.
) | ||
assert not isinstance(other, Affine) | ||
return self.__mul__(other) | ||
return NotImplemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not related to type hinting: removal of the right multiplication implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note: I'm not providing type hints for dunder methods. These are specified by the Python language.
What do you think @mwtoews ? |
You could add |
There are potentially a few more to define via:
But honestly, it looks good enough for me. |
Resolves #74