How to make a class Unpackable from plugin hook.
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
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?
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 leggendo dataclassy/mypy.py e semanal_namedtuple.py di mypy, in particolare il metodo _make citato, quindi riproduci gli esempi di reveal_type per l’iterazione di tuple e NamedTuple. Il lavoro è completato quando si è identificato come, o se, sia possibile rappresentare l’unpacking in stile tuple tramite l’hook del plugin mypy e si è fornita una risposta concreta per questo caso d’uso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100