Cannot assert a callable returns `None` when it must return `None`
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
Bug Report
mypy prevents you making assertions about callables that must return None when they're called.
This is important as not everyone works in a type-checked context, and so library code must be robust to this.
In my case, I have a chain of callables, the ones in the middle take iterables and return iterables, but the one at the start must take no arguments and the one at the end must consume the upstream iterable and return nothing.
To Reproduce
def returns_none() -> None:
pass
assert returns_none() is None
Expected Behavior
No mypy complaints
Actual Behavior
"returns_none" does not return a value (it only ever returns None) [func-returns-value]
Your Environment
- Mypy version used: mypy 1.10.1 (compiled: yes)
- Mypy command-line flags: none
- Python version used: Python 3.12.1
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 mypy 1.10.1 su Python 3.12.1 usando la funzione returns_none e l'asserzione mostrate. Traccia la diagnostica func-returns-value, quindi verifica che le asserzioni sui callable annotati per restituire None non producano alcuna segnalazione, mentre la diagnostica esistente rimanga per l'uso inappropriato di un valore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100