Generic method returning nested class
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
-
Are you reporting a bug, or opening a feature request? bug
-
Please insert below the code you are checking with mypy.
from typing import Generic, TypeVar T = TypeVar('T', bound='Base') class Base: class Inner: ... class A(Base): class Inner: ... class Foo(Generic[T]): def func(self) -> T.Inner: ... foo = Foo[A]() reveal_type(foo.func()) -
What is the actual behavior/output?
main.pyi:15: error: Revealed type is 'main.A*' -
What is the behavior/output you expect?
main.pyi:15: error: Revealed type is 'main.A.Inner*'If the analyzer is not sophisticated enough to figure this out yet, it should raise an error/warn and turn into
<nothing>rather than becoming the wrong type. -
What are the versions of mypy and Python you are using? mypy v0.701 + CPython v3.7.1
Do you see the same issue after installing mypy from Git master? yes, same results with 0.710+dev.bb7dbd5afd84656a62311e5f69a1cef6d06466bc
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 il riproduttore in main.pyi, in particolare con l'annotazione generica del valore restituito di Foo.func e la chiamata a reveal_type alla riga 15. Traccia come il type checker risolve T.Inner per Foo[A]; è completato quando segnala A.Inner invece di A, oppure emette un errore e non produce alcun tipo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100