python / python/mypy

(inter-)dependent variable types

Abierto
#7,422 2 comentarios 0 reacciones 0 asignados Ver en GitHub

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 as Union[int, str]
  • What is the behavior/output you expect?
    type of a can only be int given 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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.