Should use fully qualified names in error messages

Abierto
#4,154 5 comentarios 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
compilers

Línea de trabajo

No file, test, or entry point is named. Reproduce the reported diagnostics involving same-named classes from different modules, then trace mypy's error-message formatting and related tests. Done means diagnostics clearly distinguish the classes by their fully qualified names without obscuring the existing type information.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug priority-1-normal topic-usability

When mixing classes with the same name defined in different modules, it's possible to generate error messages like this that are a little difficult to decipher:

/tmp/my.py:19: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Future[T]], None]"; expected "Callable[[Future[T]], Any]"                                                                                 
/tmp/my.py:20: error: Argument 1 to "add_done_callback" of "Future" has incompatible type "Callable[[Arg(Future[T], 'source')], None]"; expected "Callable[[Future[T]], None]"

The actual problem was that the "Future" on one side of the error was from a different module. It's especially difficult to spot because of the unrelated superficial differences: I assumed there was some kind of significance to one side having a named Arg while the other doesn't.

I ran into this while writing something similar to asyncio.wrap_future, which converts from one library's Future class to another's, and getting the two mixed up in my type annotations.

Including the fully qualified class names would have made the error message much more obvious.

Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Merge medio
1 d 18 h
PR fusionados (30 d)
54

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.

Más de python/mypy

Todos los issues de python/mypy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.