Mypy fails to correctly validate Type[T]
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
Dear all,
Consider the example code below:
from typing import Type, TypeVar, Tuple
T = TypeVar('T')
def func(a: T, a_type: Type[T]) -> Tuple[T, Type[T]]:
return a, a_type
a1, a1_type = func(1, int)
a2, a2_type = func(1, str)
reveal_type(a1)
reveal_type(a1_type)
reveal_type(a2)
reveal_type(a2_type)
The first call to func shouldn't give rise to any issues, while the second one should complain about an incompatible type in the a_type argument (as type(1) is not str).
Yet, whenever I run mypy (Python 3.7; mypy 0.770; MacOS 10.15.1) it fails to produce any errors, even going as far to infer the type of a2 as object instead of int.
>>> mypy test.py
test.py:13: note: Revealed type is 'builtins.int'
test.py:14: note: Revealed type is 'Type[builtins.int]'
test.py:15: note: Revealed type is 'builtins.object'
test.py:16: note: Revealed type is 'Type[builtins.object]'
Is anyone familiar with this issue?
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 ejecutando el ejemplo proporcionado con mypy y comparando los tipos y diagnósticos reportados con el resultado esperado. Sigue el flujo de inferencia de tipos y validación de argumentos para Type[T]; se considera terminado cuando se rechaza func(1, str), se acepta func(1, int) y se infieren correctamente los tipos revelados.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100