Skip to content
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

Merged
merged 8 commits into from Aug 25, 2022

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Aug 24, 2022

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.

@ilevkivskyi
Copy link
Member Author

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.

@ilevkivskyi
Copy link
Member Author

Hm, actually I think currently inline mypy comments may not work at all, because they update e.g. enable_error_code, but this one is not used for anything. The Errors class uses disabled_error_codes set, that is currently computed just once in main.py.
This PR makes it a bit better (we at least correctly set options for state). But they are still not used for anything, as options for Errors are passed just once in build.py.

Let me try also fixing inline comments here.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

OK, so I now also fixed the inline error codes. 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 further adjust them

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.

@ilevkivskyi
Copy link
Member Author

@hauntsaninja This is ready for review now.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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,
Copy link
Collaborator

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, OK, makes sense.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@JukkaL JukkaL left a 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!

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@ilevkivskyi ilevkivskyi merged commit d68b1c6 into python:master Aug 25, 2022
@ilevkivskyi ilevkivskyi deleted the per-module-error-codes branch August 25, 2022 13:31
hauntsaninja added a commit to hauntsaninja/mypy that referenced this pull request Aug 25, 2022
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
hauntsaninja added a commit that referenced this pull request Aug 26, 2022
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
ilevkivskyi added a commit that referenced this pull request Sep 9, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for per-module enabling/disabling of error codes
3 participants