(🐞) unreachable `isinstance` only works with variables
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
# mypy: warn-unreachable
def foo() -> int: return 1
class A:
i: int
foo() -> int: return 1
assert isinstance(1, str)
assert isinstance(1 + 1, str)
assert isinstance(foo(), str)
assert isinstance(A.foo(), str)
assert isinstance(A().foo(), str)
assert isinstance(A().i, str)
a: A
assert isinstance(a.foo(), str)
i = 1
assert isinstance(i, str) # error: Subclass of "int" and "str" cannot exist: would have incompatible method signatures [unreachable]
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 by running the provided mypy snippet with warn-unreachable enabled and compare the isinstance expressions that do and do not produce diagnostics. Trace the type-checking path for expressions versus variables; done should mean the intended equivalent expressions receive consistent unreachable checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100