(inter-)dependent variable types
Abierto
Nadie ha tomado este issue todavía.
feature
needs discussion
priority-2-low
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
I'm not sure how to entitle this, but I think it's a dependent type.
- Are you reporting a bug, or opening a feature request? yes
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
from typing import Tuple, Union
def x() -> Union[Tuple[int, int], Tuple[str, str]]:
...
a, b = x()
if isinstance(b, int):
reveal_type(a) # can only be int but is reported as Union[int, str]
- What is the actual behavior/output?
type is reported asUnion[int, str] - What is the behavior/output you expect?
type ofacan only beintgiven the return type signature - What are the versions of mypy and Python you are using? 7.20
Do you see the same issue after installing mypy from Git master? yes - What are the mypy flags you are using? (For example --strict-optional)
python_version=3.7
I'm assuming this would be a difficult change, but I figured I'd open an issue for the sake of having a record, and in the meantime I can use assert isinstance()
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 con la reproducción mínima en Python del issue y verifica la salida actual de reveal_type con la configuración de Python 3.7 indicada. El cambio estaría completo cuando restringir b a int también restrinja a a int, manteniendo el caso correspondiente de str y el comportamiento existente para uniones no relacionadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 30/100