Make disallow-any-unimported flag invertible#18030
Conversation
| help="Disallow usage of generic types that do not specify explicit type parameters", | ||
| group=disallow_any_group, | ||
| ) | ||
| add_invertible_flag( |
There was a problem hiding this comment.
I moved this down ~20 lines or so, as all invertible flags for this group were defined after non-invertible flags prior to now and I wanted to maintain that convention (assuming this was intentional and not just a coincidence)
|
|
||
| t: Unchecked = 12 # E: Type of variable becomes "Any" due to an unfollowed import | ||
|
|
||
| [case testAllowImplicitAnyVariableDefinition] |
There was a problem hiding this comment.
I'm not fully sure how to test explicitly setting what is already the default behaviour. This test will pass whether or not --allow-any-unimported is set (as long as --disallow-any-unimported is not set).
This is a copy of the test immediately before it. The test before this sets --disallow-any-unimported and asserts that an error occurs, this test sets --allow-any-unimported and asserts no error occurs.
ad42848 to
e7d709b
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
hauntsaninja
left a comment
There was a problem hiding this comment.
Thanks! The specific change looks good.
That said, I'm obligated to disclaim that global --follow-imports=skip is evil. It's the most commonly misused mypy config I see. If someone random is reading this, you usually want --disable-error-code import-untyped or maybe --ignore-missing-imports
Absolutely agree 👍 We have The aim here is to support special cases where it may make sense to do partial type checking of a single modified file locally in a very large project (by using Use of these flags should always be an exception when manually running mypy, and not part of your standard configuration. |
The
--follow-imports=skipCLI option is pretty much unusable in a project wheredisallow_any_unimportedis set to true in the configuration file, as this results in a large number of errors (due to both flags being incompatible). We have a pretty standard project configuration file (withdisallow_any_unimported = trueandfollow_imports = 'normal'), but for specific local development cases where we want to run the mypy CLI with--follow-imports=skipit's incredibly noisy due to the number of errors produced.This change proposes making the
disallow-any-unimportedinvertible, so that the CLI can be used with--follow-imports=skipin a less noisy way by using: