Mypy can't correctly infer nested union types in some situations
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
Start by running the issue's good, bad, and good2 examples with mypy and compare the inferred types for the list literal and concatenation. Trace the nested union and list inference path, then add a regression test showing that bad() is accepted without the cast while existing type-checking behavior remains intact.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I'm not sure what the cause is here, but I documented some simple examples of this issue. I would expect all of these examples to pass the type checker, but one fails peculiarly. I wouldn't be surprised if this is the result of an existing issue, but I couldn't find it.
from typing import cast, List, Union
Scalar = Union[str, float]
def good() -> List[Scalar]:
return ["foo", 1.0]
def bad(params: List[Scalar]) -> List[Scalar]:
# error: Incompatible return value type (got List[object], expected
# List[Union[str, float]])
# error: Unsupported operand types for + (List[object] and
# List[Union[str, float]])
return ["foo", 1.0] + params
def good2(params: List[Scalar]) -> List[Scalar]:
return cast(List[Scalar], ["foo", 1.0]) + params
- 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 1/5 Menos de una hora Aptitud para principiantes 90/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
zostera/django-bootstrap4#894 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
use-agent-os/agent-os#3276 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
NousResearch/hermes-agent#117848 ·