(🐞) False error "statement is unreachable" with `NoReturn` overloaded method
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
The overloaded version has different behavior to the normal version. because it is returning NoReturn it should silence the 'unreachable' error.
from typing import overload, NoReturn
@overload
def f(a: str) -> int: ...
@overload
def f(a: str, b: NoReturn) -> NoReturn: ...
def f(a: str, b: NoReturn = ...) -> object: ...
b: bool
assert b
if not b:
f("") # error: Statement is unreachable ✅
print("hi")
if not b:
f("", b) # error: Statement is unreachable ❌
print("hi")
def f2(a: str, b: NoReturn) -> NoReturn: ...
if not b:
f2("", b) # no error ✅
print("hi")
> Test run complete: 2 passed, 1 failed <
Failures:
---------------------------
if not b:
f("", b) # error: Statement is unreachable ❌
print("hi")
---------------------------
Expected:
no error ✅
Actual:
error: Statement is 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
Use the supplied Python reproducer as the starting test case; trace how overloaded calls are checked when one matching signature returns NoReturn. Add a regression test showing that f("", b) does not trigger the unreachable-statement error, then run the relevant mypy tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100