Treat Assigning Coroutine to `_` the Same as Unused Coroutine
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
Feature
Treat assigning a function's coroutine return value to the _ variable the same as an unused coroutine.
Pitch
Mypy attempts to catch the bug of forgetting to await a coroutine by detecting unused coroutines. For example, with mypy 1.19.1:
async def foo() -> int:
return 42
def bar() -> None:
foo() # error: Value of type "Coroutine[Any, Any, int]" must be used [unused-coroutine]
It's the style convention of some organizations to assign the unused return value of a function to the _ variable. This signals to readers that the return value was intentionally ignored and not a possible bug. However, this then silences the unused-coroutine issue.
async def foo() -> int:
return 42
def bar() -> None:
_ = foo() # no mypy error
I'm not sure if there is precedent of mypy treating _ differently, but I believe that practically this would aim to catch the same category of bugs as unused-coroutine.
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
Inizia individuando la diagnostica esistente di mypy per le coroutine non utilizzate e la gestione delle assegnazioni a _. Segui l’analisi dell’esempio _=foo(), quindi verifica mediante esempi mirati di controllo dei tipi che l’assegnazione di una coroutine a _ produca la stessa diagnostica del lasciarla inutilizzata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100