-
Notifications
You must be signed in to change notification settings - Fork 165
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
Make type annotations for NumPy arrays more specific #1358
Conversation
Pull Request Test Coverage Report for Build 12776415127Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
I don't know if you want yo add it to this PR, but pyright also complains about |
I annotated it with |
You can set it to |
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.
Overall this LGTM, just one small inline question about the hint for __array__
self, dtype: np.dtype[Any] | None = ..., copy: bool | None = ... | ||
) -> npt.NDArray[Any]: ... |
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.
Do we want to use a generic/typevar here? Since the Any
for the dtype argument needs to match the dtype inside the returned array?
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.
For the record we ignore the dtype
at runtime. However, I cannot annotate the ndarray with _T
as that would be incorrect. There is a mapping from _T
to numpy types that we’d need to manually add and that is a lot of work.
Also, this method exists to support np.array
calls no one should call it directly. I think NumPy type stubs will mask this call anyway
Related to #1352
This is trying to address some complaints from
pyright
infering the NumPy array asUnknown
.