Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

attr'd classes don't have default attributes?

Aperta
#1,477 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-attrs/attrs

Tutte le issue di python-attrs/attrs

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.