python-attrs / python-attrs/attrs

Decorated functions do not work with inheritance

Open
#1,549 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.8k
Forks
480
Avg merge
2h 15m
Merged PRs (30d)
2

Description

I was trying to research how to get the class bound method instead of the function in a decorator and was looking at attrs if it figured it out, but apparently not

>>> import attrs

... @attrs.define
... class A:
...     foo: str = attrs.field()
... 
...     @foo.default
...     def _foo_default(self):
...         return "A"
... 
... @attrs.define
... class B(A):
...     def _foo_default(self):
...         return "B"
... print(A())
... print(B())
A(foo='A')
B(foo='A')  # was expecting `foo='B'` here due to overriding

Have you guys researched this topic and is there any conclusions on this?

Contributor guide

Open the contributing guide

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.

Research direction

Start by reproducing the inheritance example using attrs.define, attrs.field, and the _foo_default methods shown in the issue. Trace how the default is collected for A and B, then establish whether the behavior should change or be documented; done requires an agreed conclusion backed by a regression test or documentation update.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.