Document dataclass field should not be reused
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Documentation
The current implementation of dataclass modifies a field in place. Thereby, the following code will modify f:
from dataclasses import dataclass, field
f = field(kw_only=True)
@dataclass
class A:
x: int = f
y: int = f
print(f) # now f.name is filled
# furthermore, A is broken (or does not behave if we used two different field instance)
It can create issues when we have multiple fields that have the same spec and we reuse the same Field instance to set the same metadata to all of them. A class is created but it's garbage.
IMHO, in the docs, we should warn the user to NOT share any Field instance.
Linked PRs
- gh-145373
- gh-145387
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 la documentazione di dataclass e Field e le PR collegati gh-145373 e gh-145387. Aggiungi un avviso chiaro a non riutilizzare un’istanza di Field tra i campi di dataclass e considera completo l’esempio nell’issue quando le indicazioni documentate affrontano la mutazione risultante e il comportamento errato della classe.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100