Open
Description
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.