Avoid treating pass and ... as no-op for reachability#20488
Merged
hauntsaninja merged 2 commits intopython:masterfrom Jan 8, 2026
Merged
Avoid treating pass and ... as no-op for reachability#20488hauntsaninja merged 2 commits intopython:masterfrom
pass and ... as no-op for reachability#20488hauntsaninja merged 2 commits intopython:masterfrom
Conversation
Fixes python#16232 The inclusion of these statements dates back to the original `--warn-unreachable` PR (and doesn't provide justification) I've been advocating for more consistent heuristics for allowable unreachable code across type checkers and I can't come up with a good reason that this should be allowed
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
The aiohttp one seems kind of useful to know about, the other two are maybe a little annoying to see change on, but defensible |
Contributor
|
Would half-fix #20462, & docunenting the consensus reached at microsoft/pyright#11041 would fix the other half. |
A5rocks
approved these changes
Dec 30, 2025
Collaborator
A5rocks
left a comment
There was a problem hiding this comment.
I think there are (weak) justifications for these, but I agree with removing it.
Maybe we can remove the logic that checks multiple statements now? Maybe that's a followup.
JukkaL
reviewed
Jan 8, 2026
Collaborator
JukkaL
left a comment
There was a problem hiding this comment.
Add test?
This looks good to me.
This comment has been minimized.
This comment has been minimized.
7e4ff0c to
773289b
Compare
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/client.py:870:17: error: Statement is unreachable [unreachable]
+ aiohttp/client.py:870:17: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-unreachable for more info
Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/abc.py:2774: error: Statement is unreachable [unreachable]
pytest (https://github.com/pytest-dev/pytest)
+ testing/code/test_code.py:151: error: Statement is unreachable [unreachable]
+ testing/code/test_code.py:167: error: Statement is unreachable [unreachable]
|
This was referenced Jan 11, 2026
ilevkivskyi
pushed a commit
that referenced
this pull request
Jan 11, 2026
There is a special case about unreachability, `return NotImplemented`, which we did not until now mention, which we hereby now mention in the documentation of `--warn-unreachable`. I also add a test to test this claimed behavior thoroughly. The current test tests its desired behavior, in a class, but the actual behavior of mypy is much broader than that, and applies all the time, it seems. Fixes #20462. That issue is not correct anymore, as it was obsoleted by #20488. However, during its discussion @sterliakov brought up this `NotImplemented` edge case as something that should be documented. I think the documentation after this PR will be satisfactory by everyone's standards. Similarly, this PR closes #20558. Theoretically, there could be further special cases of unreachability of which I am not aware, but these can be noted by later PRs if so.
tyralla
added a commit
to tyralla/mypy
that referenced
this pull request
Mar 11, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #16232
The inclusion of these statements dates back to the original
--warn-unreachablePR (and doesn't provide justification)I've been advocating for more consistent heuristics for allowable unreachable code across type checkers and I can't come up with a good reason that this should be allowed