Generic method returning nested class
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
-
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem Reproducer in main.pyi, insbesondere mit der generischen Rückgabeannotation von Foo.func und dem reveal_type-Aufruf in Zeile 15. Verfolge, wie der Typprüfer T.Inner für Foo[A] auflöst; abgeschlossen ist es, wenn er A.Inner statt A meldet oder einen Fehler ausgibt und keinen Typ erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100