-
Notifications
You must be signed in to change notification settings - Fork 24
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
Enable type checking #340
Enable type checking #340
Conversation
A: Optional[Union[Real, np.ndarray]] = None, # noqa: N803 | ||
b: Optional[Union[Real, np.ndarray]] = None): | ||
A: Optional[Union[np.generic, np.ndarray]] = None, # noqa: N803 | ||
b: Optional[Union[np.generic, np.ndarray]] = None): | ||
"""Apply the affine map :math:`f(x) = A x + b` to the geometry of *mesh*.""" | ||
|
||
if isinstance(A, Real): | ||
if A is not None and not isinstance(A, np.ndarray): | ||
A = np.diag([A] * mesh.ambient_dim) # noqa: N806 | ||
|
||
if isinstance(b, Real): | ||
if b is not None and not isinstance(b, np.ndarray): |
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.
@inducer I had a little trouble here: the type checking for the numpy functions doesn't like Real
. I get this error with the original code:
meshmode/mesh/processing.py:1295: error: Argument 1 to "diag" has incompatible type "List[Real]"; expected "Union[_SupportsArray[dtype[Any]], Sequence[_SupportsArray[dtype[Any]]], Sequence[Sequence[_SupportsArray[dtype[Any]]]], Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]], Sequence[Sequence[Sequence[Sequence[_SupportsArray[dtype[Any]]]]]]]" [arg-type]
The change fixes it, but I'm not sure if there's something more specific I can use instead of np.generic
(or if this can be written in a different way to avoid the issue).
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 think this is OK for now. Mypy is still at war with Python's numerical tower, cf. python/mypy#3186 for example. I expect that this will get better with time.
LGTM, thanks! (And I've marked mypy required.) |
Splitting this out from #308 to keep the discussion separate.