ENH: Add a mypy plugin for inferring platform-specific np.number precisions#17843
ENH: Add a mypy plugin for inferring platform-specific np.number precisions#17843rgommers merged 13 commits intonumpy:masterfrom
np.number precisions#17843Conversation
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. |
Alternative to #17514.
This PR adds a mypy plugin that automatically assigns a platform-specific precision
to certain
np.numbersubclasses (or aliases thereof) while static type checking.Most notably this includes
np.int_, which is always equivalent tonp.int32on windowsbut
np.int64on most (all?) other 64-bit platforms.While #17514 attempts to accomplish this via a dynamically generated
.pyifile,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.