Do not raise `unused-awaitable` when it's already `await`ed
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
La carga útil no nombra archivos, pruebas ni puntos de entrada. Empieza por rastrear dónde mypy emite el diagnóstico unused-awaitable y cómo maneja los nodos await; el trabajo estará terminado cuando los awaitables a los que se aplica await ya no produzcan el diagnóstico, mientras que los awaitables no utilizados sigan produciéndolo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100