Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

attr'd classes don't have default attributes?

Open
#1,477 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
5.9k
Forks
499
Avg merge
3d 12h
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-attrs/attrs

All issues in python-attrs/attrs

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.