-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Allow per-module error codes #13502
Allow per-module error codes #13502
Conversation
Btw, this means that inline mypy comments for error codes will start to act as overrides after this PR. Currently they just completely replace the global config, or command line flags. |
Hm, actually I think currently inline mypy comments may not work at all, because they update e.g. Let me try also fixing inline comments here. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
OK, so I now also fixed the inline error codes. The logic is naturally like this:
So one can e.g. enable code globally, disable it for all tests in config, and then re-enable in a specific test by an inline comment. |
@hauntsaninja This is ready for review now. |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Awesome, just one nit!
mypy/errors.py
Outdated
file: str, | ||
module: str | None, | ||
scope: Scope | None = None, | ||
options: Options | None = None, |
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.
nit: Should this have a default value? Having it be required would make sure we get all call sites
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.
Yeah, OK, makes sense.
This comment has been minimized.
This comment has been minimized.
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.
Excellent, this is a very useful feature!
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Per-module error codes were added in python#13502, let's recommend using them. The existing type ignore behaviour is pretty unintuitive; I think most people actually want `# mypy: ignore-errors`. There are probably people depending on the current behaviour though. Fixes python#13435, fixes python#12076, fixes python#11999, fixes python#11027, fixes python#9318, fixes python#7839
Per-module error codes were added in #13502, let's recommend using them. The existing type ignore behaviour is pretty unintuitive; I think most people actually want `# mypy: ignore-errors`. There are probably people depending on the current behaviour though. Fixes #13435, fixes #12076, fixes #11999, fixes #11027, fixes #9318, fixes #7839
Fixes #9440 This is a bit non-trivial because I decided to make per-module code act as overrides over main section error codes. This looks more natural no me, rather that putting an adjusted list in each section. I also fix the inline `# mypy: ...` comment error codes, that are currently just ignored. The logic is naturally like this: * Command line and/or config main section set global codes * Config sections _adjust_ them per glob/module * Inline comments adjust them again So one can e.g. enable code globally, disable it for all tests in config, and then re-enable locally by an inline comment.
This page already says: > The examples in this section use inline configuration But some of these examples predate support for inline configuration of error codes that was added in python#13502
This page already says: > The examples in this section use inline configuration But some of these examples predate support for inline configuration of error codes that was added in #13502
Fixes #9440
This is a bit non-trivial because I decided to make per-module code act as overrides over main section error codes. This looks more natural no me, rather that putting an adjusted list in each section.
I also fix the inline
# mypy: ...
comment error codes, that are currently just ignored. The logic is naturally like this:So one can e.g. enable code globally, disable it for all tests in config, and then re-enable locally by an inline comment.