Skip to content

Avoid narrowing to unreachable at module level#21144

Merged
hauntsaninja merged 2 commits intopython:masterfrom
hauntsaninja:modulereach
Apr 2, 2026
Merged

Avoid narrowing to unreachable at module level#21144
hauntsaninja merged 2 commits intopython:masterfrom
hauntsaninja:modulereach

Conversation

@hauntsaninja
Copy link
Copy Markdown
Collaborator

@hauntsaninja hauntsaninja commented Apr 1, 2026

Helps with confusing symptoms in #21132

It is unfortunate that it makes the logic a little more ad hoc / might lead to minimal repros being a little more confusing. But I think this is still a better and more helpful state to be in than before #20660 (relevant PR from the narrowing rewrite).

Hopefully we can add the ability to check unreachable code, which will fix this and other issues.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not narrowing to unreachable in top-levels is fine. Top-levels are special already, e.g. we don't defer them.

@hauntsaninja hauntsaninja merged commit 232697e into python:master Apr 2, 2026
24 checks passed
@hauntsaninja hauntsaninja deleted the modulereach branch April 2, 2026 02:12
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.

2 participants