warn-unreachable false-positive when method updates attribute after assert
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Consider the following code:
from dataclasses import dataclass
@dataclass
class Foo:
value: int
modified: bool = False
def update(self) -> None:
self.value += 1
self.modified = True
foo = Foo(42)
assert not foo.modified
foo.update()
assert foo.modified
print("Reached")
When this is run, the print("Reached") line is reached, but mypy doesn't seem to realize that. Running mypy --warn-unreachable --pretty on the above code gives:
unreachable03.py:18: error: Statement is unreachable
print("Reached")
^
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: both v0.931 and the GitHub version as of commit 48d810d5ed25f898d4f220a7476b6b267c289b9a
- Mypy command-line flags:
--warn-unreachable --pretty - Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.9
- Operating system and version: macOS 11.6
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
Riproduci il report con l’esempio di dataclass fornito usando mypy --warn-unreachable --pretty, quindi traccia l’analisi del codice irraggiungibile intorno alle due asserzioni e a foo.update(). Aggiungi un test di regressione per questo esempio e verifica che print("Reached") non venga più segnalato come irraggiungibile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100