python / python/mypy

Treat Assigning Coroutine to `_` the Same as Unused Coroutine

Abierto
#20,570 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature
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

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

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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.