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

Add --warn-unused-strictness-exceptions flag #4225

Closed

Conversation

ilinum
Copy link
Collaborator

@ilinum ilinum commented Nov 8, 2017

Warn about strictness flags unnecessarily disabled for particular modules.
If a flag is enabled globally (either explicitly or by default) and it is
disabled for a particular module that does not have errors related to this
flag mypy will output an error.

Currently, this is implemented only for --disallow-any-generics but it should be
very straightforward to support other strictness flags.

Fixes #4018

@ilinum
Copy link
Collaborator Author

ilinum commented Nov 8, 2017

The tests that this PR is failing were introduced in #3952.

It's definitely a bug in collect_any_types that was there before this PR: if disallow_any=generics was enabled for a file that had a recursive definition (e.g. a recursive NamedTuple), it would crash.

@ilevkivskyi I looked at #3952 but I'm having trouble figuring it out on how to fix this particular problem. Can you give me some pointers?

@ilevkivskyi
Copy link
Member

collect_any_types happens too soon. Recursive types are "fixed" in patches after third pass. There are two options:

  • Quick and simple fix: just move to a later stage, either append patches (be sure to place them at the very end) or move to checker if possible.
  • A bit more long-term solution (that will still work if recursive types are supported) but harder to implement is to track visited type nodes while collecting.

I would recommend the first option, unless @JukkaL has a better idea.

Warn about strictness flags unnecessarily disabled for particular modules.
If a flag is enabled globally (either explicitly or by default) and it is
disabled for a particular module that does not have errors related to this
flag mypy will output an error.

Currently, this is implemented only for --disallow-any-generics but it should be
very straightforward to support other strictness flags.

Fixes python#4018
@ilinum ilinum force-pushed the warn-unused-strictness-exceptions branch from c719fa6 to 4a364ca Compare March 21, 2018 05:26
@gvanrossum
Copy link
Member

Hey @ilinum shall we abandon this? Or do you have time to bring it back into shape?

@ilinum
Copy link
Collaborator Author

ilinum commented Aug 6, 2018

No, I don't think I have enough time to work on this. If someone wants to take this over, go ahead!

@ilinum ilinum closed this Aug 6, 2018
@ilinum ilinum deleted the warn-unused-strictness-exceptions branch July 25, 2022 21:18
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.

3 participants