(🐞) False error "statement is unreachable" with `NoReturn` overloaded method
Aperta
Nessuno ha ancora preso questa issue.
bug
topic-reachability
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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 ❌
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Usa il riproduttore Python fornito come caso di test iniziale; traccia il modo in cui vengono controllate le chiamate sovraccariche quando una firma corrispondente restituisce NoReturn. Aggiungi un test di regressione che mostri che f("", b) non attiva l'errore di istruzione irraggiungibile, quindi esegui i test mypy pertinenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100