How to make a class Unpackable from plugin hook.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Hi guys,
I am trying to add mypy support for dataclassy, which is a replacement for standard dataclasses.
You can see the code here:
https://github.com/biqqles/dataclassy/blob/15cef524b55df2c65b39d1619c7b8f1a3d28a813/dataclassy/mypy.py
One of the problems I've run in to is in supporting the feature of dataclassy that allows its dataclasses to be unpacked like tuples.
Firstly, I couldn't figure out how to represent tuple style unpacking in the mypy type system. If I create a class with def __iter__(self) -> Iterable[int], then it works, but I can't seem to do anything like Iterable[int, int, str, bool]. When I reveal_type for a NamedTuple.__iter__ I just see a generic iterator typing.Iterator[_T_co]. I see that reveal_type((1, 'foo').__iter__()) is typing.Iterator[builtins.object*]
So I tried to figure out if there was special logic in semanal_namedtuple.py but I couldn't see anything there other than adding Iterable as a base in the _make method(?) which doesn't seem like that I need. And, besides, I figure wherever the logic is it must also apply to regular tuples too.
What am I missing?
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
Lies zuerst dataclassy/mypy.py und mypys semanal_namedtuple.py, insbesondere die referenzierte _make-Methode, und reproduziere dann die reveal_type-Beispiele für die Iteration über tuple und NamedTuple. Erledigt ist die Aufgabe, wenn festgestellt wurde, wie oder ob sich tuple-artiges Entpacken über den mypy-Plugin-Hook darstellen lässt, und eine konkrete Antwort für diesen Anwendungsfall vorliegt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100