(inter-)dependent variable types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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()
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione minima in Python nell’issue e verifica l’output attuale di reveal_type con la configurazione Python 3.7 indicata. La modifica sarebbe completa quando restringere b a int restringerà anche a a int, preservando al contempo il caso str corrispondente e il comportamento esistente per le union non correlate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 30/100