-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-104504: Cases generator: enable mypy's possibly-undefined
error code
#108454
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
Merged
AlexWaygood
merged 4 commits into
python:main
from
AlexWaygood:possibly-undefined-cases
Aug 25, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hm. When I manually run
I still get an error for this line:
(Also for
popped
, but I'm usingformat
as the simpler example to get right first.)FWIW maybe the variable could be named
fmt
? IMOmaybe_format
is a bit unwieldy and not all that helpful. Using an abbreviation intuitively conveys the idea that this is a more local use thanformat
.Not sure how to fix that error I get -- maybe it wants an assignment to
format
in the unreachablecase _
clause, or maybe we need to just addformat: str | None = None
at the top (just beforematch
) and just addassert format is not None
vefore adding it to the set? Then we can get rid ofmaybe_format
again.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.
That's strange. I can reproduce your results locally if I use that command, but not if I run
mypy --config-file Tools/cases_generator/mypy.ini
(which is the command we're running in CI). And I know that before I made the code changes,mypy --config-file Tools/cases_generator/mypy.ini
was resulting inpossibly-undefined
errors on these lines.I wonder why the two commands are leading to different results? It seems very odd.
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.
@hauntsaninja, any idea what might be going on here? :)
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.
This diff would fix the error you're seeing when you're running mypy with the different invocation, but I still don't understand why the two different mypy invocations are producing different results (and the errors you're seeing with the different mypy invocation feel spurious, since mypy's well aware that these
match
statements are exhaustive):Possible fix:
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.
If I comment out
warn_unreachable = True
in the mypy.ini file, it produces those warnings. So that flag may not mean what we think it means.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.
Looks like we simultaneously figured this out here 😄
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.
Hmm that's weird. Not familiar with the undefined stuff, let me go get pdb out from my closet
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.
ISTM that there are probably two mypy bugs we've stumbled upon here (☹️ ):
--warn-unreachable
should never be making errors go away: if mypy reports these errors without--warn-unreachable
, it should probably report them with--warn-unreachable
as wellpossibly-undefined
errors with or without--warn-unreachable
specified, since mypy's well aware that thesematch
statements are exhaustive, so it's not possible to get to the end of thematch thing
statement withoutformat
being assigned to.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.
Sorry for the comment earlier that was a repeat of what you already found, my Github was stale.
I need to get back to work, but it looks like there's some sort of side-effect-y message filtering that's going on in a place that to me seems like it absolutely should not have side effects. This diff makes mypy consistently not error:
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.
Found some more time to look at this, I think python/mypy#15995 should fix