reassignment of a `TypeAliasType` should not be evaluated as type expression
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Reproduce el comportamiento reportado con el ejemplo de mypy-play enlazado y compara B = A con B = A[Any], incluidos los diagnósticos del modo estricto y los tipos revelados. Rastrea cómo se interpretan las asignaciones que involucran un TypeAliasType genérico y añade cobertura específica que demuestre que la reasignación conserva el objeto alias y no produce un error por falta de parámetros de tipo.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Unsurpringly, reassigning some generic TypeAliasType named A as B = A is not the same as subscripting it as B = A[Any]:
>>> type A[T] = T | str
>>> B = A
>>> type(A)
<class 'typing.TypeAliasType'>
>>> type(B)
<class 'typing.TypeAliasType'>
>>> A is B
True
Mypy's behavior (on master and 1.18.2) contradicts this:
type A[T] = T | T # ✔️ true negative
B = A # ❌ false positive: Missing type parameters for generic type "A" [type-arg]
reveal_type(A) # ✔️ mypy: "typing.TypeAliasType", runtime: "typing.TypeAliasType"
reveal_type(B) # ❌ mypy: "types.UnionType[Any, Any]", runtime: "typing.TypeAliasType"
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=962d28cd59eff168c9cd2057e9f18f88
The error at line 2 is only reported in strict mode, so if you don't use that, I can imagine that it can be rather difficult to debug.
I realize that mypy interprets B = A as if it's B: TypeAlias = A, and it's not like there's nothing to be said for that. But I think that it's rather unlikely that a someone using the type keyword would expect that omitting it would result in the exact same behavior.
For _: TypeAlias that's a different story, and is currently working fine IMO; so I'm purely talking about TypeAliasType here. And given the differences in runtime semantics between the two, I think it's fair to treat them differently.
p.s. congratz with the 20k stars!
- 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
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.
Más de python/mypy
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
bug topic-configuration topic-error-reporting
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Todos los issues de python/mypy
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
bancolombia/sentinel#23 ·
-
test md AbiertoCI
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100