python / python/mypy

Do not raise `unused-awaitable` when it's already `await`ed

Abierto
#14,795 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature topic-async
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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.