Skip to content

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

Closed
ilinum wants to merge 1 commit into
python:masterfrom
ilinum:warn-unused-strictness-exceptions
Closed

Add --warn-unused-strictness-exceptions flag#4225
ilinum wants to merge 1 commit into
python:masterfrom
ilinum:warn-unused-strictness-exceptions

Conversation

@ilinum

@ilinum ilinum commented Nov 8, 2017

Copy link
Copy Markdown
Collaborator

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

ilinum commented Nov 8, 2017

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
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
Copy Markdown
Member

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

@ilinum

ilinum commented Aug 6, 2018

Copy link
Copy Markdown
Collaborator Author

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