Cannot assert a callable returns `None` when it must return `None`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere den Bericht mit mypy 1.10.1 unter Python 3.12.1 unter Verwendung der gezeigten returns_none-Funktion und Assertion. Verfolge die Diagnose func-returns-value und überprüfe anschließend, dass Assertions über Callables, die mit dem Rückgabewert None annotiert sind, keine Beanstandung erzeugen, während die bestehende Diagnose für eine unangemessene Verwendung eines Werts erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100