Do not raise `unused-awaitable` when it's already `await`ed
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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.
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
Die Nutzlast nennt keine Dateien, Tests oder Einstiegspunkte. Beginne damit, nachzuverfolgen, wo mypy die unused-awaitable-Diagnose ausgibt und wie es await-Knoten behandelt; abgeschlossen ist die Arbeit, wenn awaitete Awaitables die Diagnose nicht mehr auslösen, während nicht verwendete Awaitables dies weiterhin tun.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100