-
Notifications
You must be signed in to change notification settings - Fork 306
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
Decide on preferred set of mypy
rules to adopt
#2589
Comments
I forget the error this raises, but: def fcn(x:None| int = None):
if x is None:
x = 0
y = x + 1 This raises a mypy error because it thinks x can still be None on the last line, and it drives me crazy since this is a pretty common design pattern! |
Huh, the mypy error I get from that is I'm wondering if it may be associated with untyped decorators (like Thank you for bringing this up! |
Ah, maybe it is related to decorators? I'll keep an eye out for next time. Here's another pytest specific one def test_fcn(ex : Exception | None):
with pytest.raises(ex):
... For some reason mypy is looking for an overloaded function (raising |
Interesting! I believe the pytest API changed recently so that |
When trying to add PlasmaPy/src/plasmapy/particles/decorators.py Lines 525 to 533 in ca92246
The "issue" is that the individual This was frustrating trying to debug. The only way I could think was to use nested conditionals, which then ruff complains about. The solution I used was just to tell mypy to ignore it I don't know if there's any more clever way. |
Description of improvement
In the last few months, we have had a flurry of pull requests to add static type checking with mypy to PlasmaPy's continuous integration suite. The current version of
mypy.ini
defines which mypy rules to ignore on a per-file and per-error basis (#2424), while having the global settings be approximately mypy's strict mode by default. New files would be checked against mypy's strict mode, while existing files have errors be ignored. We should decide on the "final" set of mypy rules to adopt.Motivation
Enabling static type checking with mypy comes with a bunch of tradeoffs. Having accurate type hint annotations can help with code readability and finding errors, but at the cost of making it hard for making a code contribution. We don't need to enable all of mypy's strict rule set, as it's possible an intermediate level would be most appropriate.
Implementation strategy
We should use this issue as a place to keep track of the rules that are difficult to deal with or that we end up ignoring a lot (using
# type: ignore[...]
). We can decide later on if the benefits of the rules are worth the tradeoffs.These rules need not be the same for every subpackage, as suggested in #2438. For example,
plasmapy.particles
is used throughout the rest of the package, so having more strict typing requirements would be appropriate.Additional context
Cross-references: #268, #2424, #2432, #2534, #2435, #2438, #2444, #2527
The text was updated successfully, but these errors were encountered: