Protocol with nested class
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
Hey,
I don't know if this a bug report, feature request or simply a question about how to do it right 😄
For proper typing I need to overload the type annotation based on the argument types. One type involved is a Protocol. Everything works as expected as long as the Protocol consists of properties or method. But as soon as I'm looking for a class within the Protocol, mypy cannot find an overload variant. (See below)
(A clear and concise description of what the bug is.)
To Reproduce
This works:
https://mypy-play.net/?mypy=latest&python=3.11&gist=d750eefc830c2080d989a7437ca518b6
This fails:
https://mypy-play.net/?mypy=latest&python=3.11&gist=0e424fbd22d314764a0d13ac9f8fe0b5
main.py:40: error: No overload variant of "create" of "Client" matches argument type "Content" [call-overload]
main.py:40: note: Possible overload variants:
main.py:40: note: def [_SupportsConfig <: SupportsConfig] create(self, content: _SupportsConfig) -> _SupportsConfig
main.py:40: note: def [_SupportsConfig <: SupportsConfig] create(self, content: _SupportsConfig, result_class: None) -> _SupportsConfig
main.py:40: note: def [_SupportsConfig <: SupportsConfig, _T] create(self, content: _SupportsConfig, result_class: type[_T]) -> _T
So, do I have to achieve my goal?
fin swimmer
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 damit, die im Issue verlinkten funktionierenden und fehlschlagenden mypy-play-Reproduktionen zu vergleichen, wobei die gemeldeten Python 3.11-Beispiele und die overload-Diagnose als Ausgangspunkt dienen. Verfolge, wie mypy mit einem Protocol umgeht, das properties oder methods enthält, im Vergleich zu einer nested class, und stelle anschließend fest, ob es sich bei dem Verhalten um einen Fehler oder ein nicht unterstütztes Muster handelt, und dokumentiere das Ergebnis.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100