attr'd classes don't have default attributes?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Start by running the issue's @define, field, and deletion example to reproduce the AttributeError, then inspect how attrs handles defaults after an instance attribute is deleted. Compare the behavior with the dataclass and hand-written class examples. Done means either the default is restored as expected or the manual prominently documents this pitfall and related migration concerns.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Today I stumbled over this one:
from attrs import define,field
from dataclasses import dataclass
@define
class N1:
foo:int|None = field(default=None)
class N2:
foo:int|None = None
def __init__(self, foo):
self.foo = 123
@dataclass
class N3:
foo:int|None = None
n3 = N3(foo=123)
del n3.foo
assert n3.foo is None
n2 = N2(foo=123)
del n2.foo
assert n2.foo is None
n1 = N1(foo=123)
del n1.foo
n1.foo # AttributeError
This is not what I'd expect when I decide to attrs-ize an existing class. Thus please either fix this, or add a reasonably prominent section that documents this (and other possible pitfalls) to the manual.
- Lingua principale
- Python
- Stelle
- 5.8k
- Fork
- 480
- Merge medio
- 2h 15m
- PR unite (30g)
- 2
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.
Altre issue di python-attrs/attrs
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
python-attrs/attrs#1620 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
python-attrs/attrs#1596 · 2 commenti · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
python-attrs/attrs#1549 · 3 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
python-attrs/attrs#1543 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
python-attrs/attrs#1532 ·
Tutte le issue di python-attrs/attrs
Issue simili
-
area: harness bug status: needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Human-Agent-Society/reef#625 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
learningequality/kolibri#15351 · 2 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Name consistency Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
eellak/triplestore#65 · 1 commento ·