TypeVar with Type-based constraints misbehaving when used to annotate *args
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
Bug Report
It seems that the below combination of *args, and TypeVar with constraints related to Type, is misbehaving. I reached out on the Gitter and was instructed that this is probably a bug.
I tried replacing the Types with ints (observable in the linked mypy-playground) and that seems to work fine.
To Reproduce
from typing import TypeVar, List, Type
TypeArgT = TypeVar("TypeArgT", Type, List[Type])
def type_a(*args: TypeArgT):
...
def type_b(*args: List[Type]):
...
type_a(int, str, float) # test t1
type_a([str, float], [int]) # test t2 <-- this does not work
type_b([bool, bool], [str, bool]) # test t3
https://mypy-play.net/?mypy=0.780&python=3.8&gist=847224369f6bad4d74a1ccfd672fb250
Actual Behavior
Test t2 in the above snippet throws the following mypy error:
main.py:14: error: Value of type variable "TypeArgT" of "type_a" cannot be "object"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.790
- Python version used: 3.8
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
No se nombra ningún archivo de proyecto ni ninguna prueba. Empieza ejecutando la reproducción con mypy 0.790 y, después, sigue la inferencia de los valores de TypeVar restringidos que se usan con *args; se considera terminado cuando t2 se acepta sin cambiar el comportamiento existente de t1 y t3.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers, devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100