Dataclass field ordering should not be enforced when init=False
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
Dataclasses support fields that have default values. All fields with defaults must appear after all fields without default values. Mypy enforces this ordering requirement and emits an error ("Attributes without a default cannot follow attributes with one") if it is violated. Pyright does the same.
By default, dataclasses include a synthesized __init__ method, but this behavior can be overridden by including an init=False argument to the dataclass decorator.
A pyright user recently submitted a bug report indicating that the field order requirement should not be enforced when init=False. I've re-read PEP 557, and it doesn't provide clarity on this point.
Either mypy and pyright are both doing the right thing here or both of them have a bug.
Perhaps someone who was involved in the development of PEP 557, the dataclass implementation, or the mypy dataclass internal plugin could help clarify which behavior is correct?
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 esaminando PEP 557, l’implementazione di dataclass e il plugin interno dataclass di mypy, quindi confronta il comportamento segnalato in pyright issue 1753. Determina se l’errore relativo all’ordine dei campi debba applicarsi quando il decoratore dataclass usa init=False, quindi documenta o implementa il comportamento concordato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100