Treat Assigning Coroutine to `_` the Same as Unused Coroutine
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
Treat assigning a function's coroutine return value to the _ variable the same as an unused coroutine.
Pitch
Mypy attempts to catch the bug of forgetting to await a coroutine by detecting unused coroutines. For example, with mypy 1.19.1:
async def foo() -> int:
return 42
def bar() -> None:
foo() # error: Value of type "Coroutine[Any, Any, int]" must be used [unused-coroutine]
It's the style convention of some organizations to assign the unused return value of a function to the _ variable. This signals to readers that the return value was intentionally ignored and not a possible bug. However, this then silences the unused-coroutine issue.
async def foo() -> int:
return 42
def bar() -> None:
_ = foo() # no mypy error
I'm not sure if there is precedent of mypy treating _ differently, but I believe that practically this would aim to catch the same category of bugs as unused-coroutine.
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
Comienza localizando el diagnóstico existente de mypy para las coroutines no utilizadas y el tratamiento de las asignaciones a _. Sigue cómo se analiza el ejemplo _=foo() y, a continuación, verifica mediante ejemplos de comprobación de tipos específicos que asignar una coroutine a _ produce el mismo diagnóstico que dejarla sin utilizar.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100