attr'd classes don't have default attributes?
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/attrs
-
Docs: `attrs.filters` is missing stated examplesPossibly taken @feiiiiii5 claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
python-attrs/attrs#1627 ·
Maintainers usually reply within 1 day
-
slots declared on attrs-decorated class are ignored/lostPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
python-attrs/attrs#1637 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
Maintainers usually reply within 1 day
-
Incorrect annotation for forward reference in generated constructorPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Decorated functions do not work with inheritancePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
Maintainers usually reply within 1 day
All issues in python-attrs/attrs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
LearningCircuit/local-deep-research#7206 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
chingu-voyages/V62-tier3-team-33#285 ·
Maintainers usually reply within 1 day
-
Proxy drops log notifications from backends that don't send FastMCP's msg/extra dictPossibly taken @asasemahmed claimed this today. Openbug server
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[Bug]: Bedrock request metadata forwarding does not work for /embeddingsPossibly taken A pull request linked to this issue is open or already merged. Openbug llm translation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day