-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix config file parsing of disallow_any/disallow_untyped_defs combination #4076
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
Conversation
mypy_self_check.ini
Outdated
|
||
# historical exception | ||
[mypy-mypy.semanal] | ||
strict_optional = False | ||
|
||
# needs py2 compatibility |
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.
I'm not sure this is true, but the file is syntactically valid in Python 2 and it tests a piece of code (mypy_extensions.py) that is supposed to work in Python 2. @ilevkivskyi can you confirm?
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.
Yes, this file supposed to run on both Python 3 and Python 2. There are still some problem with type checking it, but there is a separate issue for this #2755
Thanks for finding this. I have to agree that I would rather get rid of one of the two spellings (your second bullet). I also dislike the double negative of "disallow_any = unannotated" so I would prefer to get rid of that. FWIW I also would prefer to have a bunch of separate Boolean flags instead of the single complex flag that is (That problem, FWIW, is that if you want to have |
Let's do this for now:
Does that sound good? |
That sounds good to me! I am also okay with replacing |
I propose to just drop it. People who use it will get failures after they update (possibly at 0.540 already, which will be frozen this Friday and released Wednesday next week) but IMO that's fine, people always test new releases somewhat when they upgrade. The only thing we might add would be to have a special case in the error message that checks if |
The PR has merge conflicts. |
Fixed. |
Fixes #4075.
Due to the way
disallow_any
is parsed in config files, anydisallow_any
directive basically overrodedisallow_untyped_defs
. This confused me in #4075, and it also meant thatdisallow_untyped_defs
was implicitly disabled for mypy itself, because of the waymypy_self_check.ini
was written.This PR solves the problem by making
disallow_any
overridedisallow_untyped_defs
only if the config file either hasdisallow_any =
(disabling alldisallow_any
checks) or explicitly listsunannotated
(enablingdisallow_untyped_defs
). This passes all tests (including a new one), but it's awkward because it makesunannotated
behave differently from otherdisallow_any
flags: if a more general config hasdisallow_any = A B
and a more specific one hasdisallow_any = A
, thenB
should be disabled, but this is no longer true forunannotated
.Here are two other options for solving the problem:
disallow_untyped_defs
anddisallow_any
completely independently, and just AND them at runtime when we check whether to give an error for an untyped def. This leads to an awkward situation because now if you have bothdisallow_any = unannotated
in a general config anddisallow_untyped_defs = False
in the specific one, untyped defs still produce errors.disallow_untyped_defs
is more intuitively named. What if we just get rid ofdisallow_any = unannotated
instead?In this PR I also fix the untyped defs that crept into mypy itself due to the bug.