-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
CI, TYP: Large-scale integration type-testing with mypy_primer
#28054
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
Comments
python/typeshed#11830 (comment) and python/typeshed#13021 (comment) are examples of how it's used by |
This would be very useful. It may also be helpful to do this on a cron against the nightly wheels. And we may need to choose mypy vs pyright, depending on what the project itself uses (they may no longer be making an effort to be compatible with mypy, e.g.). |
There will be cases when we will deliberately choose to ignore the mypy_primer output. So I can imagine that doing this periodically would be more annoying than it would be helpful 🤔.
Unlike the name suggests, |
Isn't the problem that there are very few external projects to run CI on that actually have good type annotations? I'm thinking that a single job to sometimes run against The usual solution for this problem that we encourage is for downstream packages to test numpy nightlies. Quite a few projects do this now, so getting them to run their typing tests as well on those nightlies if they have any is probably more effective. |
Yes, we'd be happy to add a daily/weekly check like that to skimage and the SP Lecture Notes, e.g. |
It doesn't matter if the projects are currently correctly typed, or even typed at all. Mypy_primer reports the diffs of the mypy/pyright outputs of that project, that our change causes. |
Awesome that you already thought of this! I went ahead and added a few features to mypy_primer to make this easy to add to numpy.
I was able to get some potentially believable output with:
where I checked out numpy v2.1.3 and v2.2.0 to nump1 and nump2 respectively. Make sure to explicitly set mypy_primer supports pyright and mypy. It probably also supports basedpyright via the I do see mypy hit some errors when using v2.1.3 on the lines of Anything I should know before opening a PR? |
Wow, thanks a lot for that @hauntsaninja, that indeed sounds very helpful.
Hmm, maybe it has something to do with the mypy plugin (https://github.com/numpy/numpy/blob/main/numpy/typing/mypy_plugin.py)? It is used for system-dependent scalar types, like
Nothing in particular I suppose. |
Thanks! Ah, the plugin is a good guess. It looks like the plugin imports numpy but I didn't bother rebuilding numpy, so it's possible I introduced some skew. |
Our type-tests aren't perfect, we don't type-check our stubs, and don't use stubtest. But even if we would do all that, there's always a chance that seemingly innocent changes to the stubs could unintentionally lead to unforeseen typing issues in downstream packages.
The
mypy_primer
tool was built to help with issues like these, and helps reduce the number of these static-typing-related unknown unknowns.From https://github.com/hauntsaninja/mypy_primer
README.MD
:I have little knowledge about NumPy's CI, but I think it could help a lot if we could incorporate mypy_primer in it, and preferably run it only if changes are made to at least one
.pyi
stub file.The text was updated successfully, but these errors were encountered: