Skip to content

Conversation

@brovoski69
Copy link

This PR clarifies the documentation for the --warn-unreachable option by explaining that unreachable pass statements are intentionally not reported, and adds a small example for clarity.

Fixes #20462

@wyattscarpenter
Copy link
Contributor

wyattscarpenter commented Jan 11, 2026

This is untrue now because of #20488.

The test testPassAndEllipsisUnreachable is basically your example code, but the opposite behavior. That test passes, while your example code is unfortunately not automatically typechecked so nothing complains that its expectation is wrong.

For some reason, I can't replicate this on mypy-play.net to link you to some proof, even using its "master branch" setting (probably it's just not quite up-to-date). But, I pasted your example code into a local file and ran mypy tmp.py --warn-unreachable on it and I can confirm that on master one gets a tmp.py:4: error: Statement is unreachable [unreachable].

So, thanks for the effort, but we already obsoleted this! 😄

@brovoski69
Copy link
Author

Thanks for the detailed explanation and for checking locally, which makes sense now. I wasn’t aware of the change introduced by #20488. Agreed that this documentation update is now obsolete. Thanks for the clarification, and I appreciate the review!

pull bot pushed a commit to Hawthorne001/mypy that referenced this pull request Jan 11, 2026
…0561)

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 python#20462. That issue is not
correct anymore, as it was obsoleted by
python#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 python#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.
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.

Documentation: --warn-unreachable should clarify special handling of pass statements

2 participants