Incorrect inference of type parameter for a generic container
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
Piste de recherche
Start by running the supplied minimal reproduction through mypy and compare the two reveal_type results. Trace generic Iterable inference for B and list's constructor checking, then add regression coverage for the expected list[Y*] result and for accepting B as Iterable[Y].
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
from typing import *
T = TypeVar('T', bound='A')
class X: ...
class Y(X): ...
class A(Iterable[X]):
def __iter__(self) -> Iterator[X]: ...
class B(A, Iterable[Y]):
def __iter__(self) -> Iterator[Y]: ...
b = B()
for x in b:
reveal_type(x) # 'Y*'
y = list(b)
reveal_type(y) # 'builtins.list[X*]'
The first reveal_type is correct.
The second is wrong: it should be builtins.list[Y*]. Somehow the presence of A in the bases of B causes this mistake.
In addition, even a workaround doesn't work:
z = List[Y](b) # Argument 1 to "list" has incompatible type "B"; expected Iterable[Y]
reveal_type(z) # 'builtins.list[Y*]'
The revealed type is now correct, but the constructor doesn't pass the type check.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Merge moyen
- 1 j 18 h
- PR mergées (30 j)
- 54
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.
Autres issues de python/mypy
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
bug topic-configuration topic-error-reporting
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Toutes les issues de python/mypy
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
zostera/django-bootstrap4#894 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
use-agent-os/agent-os#3276 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
NousResearch/hermes-agent#117848 ·