Do not raise `unused-awaitable` when it's already `await`ed
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
Example:
from collections.abc import Generator
from typing import Any
from typing_extensions import Self
class MyAwaitable:
def __await__(self) -> Generator[Any, None, Self]:
return self.do_something().__await__()
async def do_something(self) -> Self:
# await self.do_async_stuff()
return self
async def _() -> None:
MyAwaitable() # (correct) error: Value of type "MyAwaitable" must be used [unused-awaitable]
await MyAwaitable() # (incorrect, already awaited) error: Value of type "MyAwaitable" must be used [unused-awaitable]
await (await MyAwaitable()) # (again incorrect) error: Value of type "MyAwaitable" must be used [unused-awaitable]
Pitch
I've encountered this while creating a class with an async constructor using __await__, like this:
class AsyncClass:
def __await__(self) -> Generator[Any, None, Self]:
return self.__ainit__().__await__()
async def __ainit__(self) -> Self:
return self
I don't think it's very useful to suggest adding an await when it's already there.
This could be done by checking if the object that's an unused Awaitable is an await node.
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
Il payload non indica file, test o punti di ingresso. Inizia tracciando dove mypy emette la diagnostica unused-awaitable e come gestisce i nodi await; il lavoro è completo quando gli awaitable sottoposti ad await non producono più la diagnostica, mentre gli awaitable inutilizzati continuano a produrla.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100