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
ENH: Add a mypy plugin for inferring platform-specific np.number
precisions
#17843
Conversation
0f46507
to
f21c8f6
Compare
f85ceba
to
0a5be9f
Compare
Interesting, tricky puzzle to get the details of this typing right. I'm not sure if one approach is clearly preferable to the other. The mypy plugin may possibly be slightly more robust to situations like cross-compiling (e.g. there's an open PR for ARM64 build on Windows, which may get the On the other hand, the plugin approach will require the user to add it in their own |
The runtime overhead should still be zero, as the new |
Yeah I get that - I meant runtime of |
Ah right, when running mypy on the script below I'm observing a minor increase in runtime when initially generating the mypy cache (~7.4 vs ~7.8 sec). Once the cache has been generated the difference disappears in its entirety though (~0.4 sec in both cases). import numpy as np |
Needs rebase. |
Yup, I'm planning on adding the release note + rebase later this evening. |
b1b047e
to
5c7c22a
Compare
Alright, the branch has been rebased and a release note (5c7c22a) has been added. |
This accumulated another merge conflict unfortunately. |
Give me a sec. |
Since `intp` is now annotated it can be used in place of `signedinteger[Any]`
Fixes an issue where the `pypy` tests would fail
Co-Authored-By: Eric Wieser <425260+eric-wieser@users.noreply.github.com>
5c7c22a
to
75c532d
Compare
And the conflict has been resolved. |
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.
Thanks @BvB93, in it goes!
Alternative to #17514.
This PR adds a mypy plugin that automatically assigns a platform-specific precision
to certain
np.number
subclasses (or aliases thereof) while static type checking.Most notably this includes
np.int_
, which is always equivalent tonp.int32
on windowsbut
np.int64
on most (all?) other 64-bit platforms.While #17514 attempts to accomplish this via a dynamically generated
.pyi
file,this PR instead uses a mypy plugin. Note that while usage of the plugin is completelly
optional, without it the precision of the likes of
np.int_
will be inferred asAny
.