(🐞) Inconsistent reachability depending if module level or not
Open
Nobody has claimed this yet.
bug
topic-reachability
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Really strange behavior here, when this statement is on the module level it creates a silently unreachable branch, but when in a scope it doesn't create unreachable
import sys
def foo() -> None:
assert sys.platform == "AMONGUS"
a # error, reachable ❌
cond: bool
if cond:
assert sys.platform == "AMONGUS"
a # error, reachable ❌
assert sys.platform == "AMONGUS"
a # no error, silent unreachable ✅
Related #11438
Related #11361
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the playground reproduction and compare the module-level and scoped cases, then read related issues #11438 and #11361 for context. Trace mypy's reachability analysis and add regression coverage for both forms; done means warn-unreachable reports the behavior consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100