(inter-)dependent variable types
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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()
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la reproduction Python minimale dans l’issue et vérifiez la sortie actuelle de reveal_type avec la configuration Python 3.7 indiquée. La modification serait terminée lorsque le fait de restreindre b à int restreindra également a à int, tout en préservant le cas str correspondant et le comportement existant pour les unions sans rapport.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 30/100