-
Notifications
You must be signed in to change notification settings - Fork 104
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
Add optional mypy check #505
base: main
Are you sure you want to change the base?
Conversation
/ok to test |
|
/ok to test |
I developed the feeling that mypy is losing momentum. So I asked like this:
Picking out one point from the response:
I believe supporting "editor-level feedback" is the single most valuable motivation for investing time into typing. — Other than that, in my experience, typing is only a moderate win overall. (ruff gives us a lot of protections already.) I see from the CI output that we have a sizable cleanup job. Do we want to target mypy, or pyright? There is probably a big overlap, but I expect that we'll spend a significant fraction of time dealing with idiosyncrasies of one or the other. |
Are there examples of projects using pyright for enforcing type checks in CI? I looked at some existing "big" Python projects to see what they were using: |
Would it make sense to integrate this with |
Here's how the pre-commit results get reported: https://results.pre-commit.ci/run/github/381173759/1741612446.WIQqJeAMSMy0Q8RPtY3MbA If we made the |
But yes, ultimately I would like for type checking to be part of the pre-commit step (not as a standalone check) |
I think mypy is really unfriendly to array libraries like NumPy and it's being discussed to move away to pyright or basedpyright. @seberg was involved in long discussions like numpy/numpy#27957 and numpy/numpy#28076. But it is unclear to me why we wouldn't like mypy in cuda.core. I guess we need to go over the list of all failures and decide. |
Yeah my limited understanding about pre-commit.ci is the same. We can't make certain pre-commit steps optional. So moving this check to pre-commit in the future SGTM. |
What I had in mind is optimizing for what the user community cares about the most. I'm assuming that's type hints in code editors. I could be wrong. |
Yeah, it could be that NumPy will use There was also sentiment that mypy has more bugs (I suspect there is reason for it). But unless you run into those, I am not aware that mypy is problematic, and I think it is still wider used in our projects. [1] The main specific issues in NumPy revolved around issues related to shape/dtype typing (e.g. |
We could exclude the mypy task from pre-commit in the CI run for now and then have a separate optional job that runs only the mypy task? This way developers using pre-commit locally get mypy as part of their workflow unless they opt out of it, but it remains optional to get PRs through until we hit a later point. |
I'm running pre-commit all the time while developing, so that I don't have to manually format my code or watch out for obsolete imports, etc. If pre-commit becomes noisy, it'll slow me down. I'll probably comment out the mypy section locally in .pre-commit.yaml. I believe it will be most productive to make a clear decision: When do we want to spend the time making our code mypy compatible? As soon as pre-commit is clean, we're done, without any extra work on the CI side. To add in my estimated effort for making cuda.core mypy compatible: couple days to one week. For me specifically: I'd (finally) jump the barrier installing Cursor and ask it to help me. Then it might be even faster. |
How do we want to proceed here? There are two questions here that are unresolved: Should we even use mypy for type checking?My 2c is that we should. There's a lot of collective experience using MyPy both within NVIDIA and the wider open-source community. While it can absolutely be fiddly at times, I've almost always been able to quickly find resolutions on StackOverflow or GitHub issues. Also tools like https://mypy-play.net/ are great for debugging. Note that using mypy to enforce type checks doesn't preclude using pyright with LSP or your IDE locally. Should we invoke mypy via pre-commit?I don't have a very strong opinion here. I definitely think we should eventually invoke mypy via pre-commit. In the interim, I just don't know how exactly to achieve what @kkraus14 is suggesting here:
|
I don't have strong opinions here. It's definitely a good start.
Assuming we have pre-commit type checking, and we've made the code compatible (no errors), would we want to keep the type checking CI job? |
Nope, at that point it goes away. The point of this PR is just to have somewhere that the results of type checking are visible |
TBH, just thinking about what I'd do:
|
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.
LGTM, mainly for the cuda_bindings/pyproject.toml change.
OK - thanks. I opened this PR for review so that it's mergeable. I'd defer to you or @leofang if/whether to merge this - no objections either way from me |
/ok to test |
/ok to test |
/ok to test |
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.
what does this overrides
section do?
You'd use the
It would be optional in the sense that it wouldn't be required to pass in CI to merge PRs, but would be opt-out for developers where they'd need to add an environment variable of |
btw let's hold off merging until code freeze is lifted (we're still wrapping up v0.2.0). Another question that just occurred to me is: If we add |
Cross-referencing #527 — A very quick experiment, trying to use Cursor to add typing annotations. |
No description provided.