Support abstract functionality for attrs classes
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- python
- Domain
- developer-experience
Research direction
Start from the requested @abstract and @override behavior in the issue's Parent/Child example, then investigate how attrs currently handles generated classes and inheritance. Done would require a decided, documented design for rejecting abstract instantiation and invalid overrides, along with corresponding tests.
Written by the indexing model from the issue text.
Description
I'd love to do something like:
@attr.s(auto_attribs=True, frozen=True)
class Parent:
@abstract
param: str
@attr.s(auto_attribs=True, frozen=True)
class Child(Parent):
@override
param = "test"
where you wouldn't be able to create an instance of a class with @abstract decorators, and you wouldn't be able to put the @override decorator on something that wasn't defined in the parent.
I commonly use attrs classes to hold configuration parameters, and allowing this functionality would make it much safer and more readable. Currently it's too easy to accidentally think you're overriding something in Child that's actually not defined in Parent (typo, got removed, etc) - and it's not clear when reading Child whether an attribute is new to the child or just overriding a default value from the parent. And leaving a value without a default in Parent is a little annoying because you have to put all the attrs without default first (which is not a big deal, but disrupts the logical grouping of members of the class).
I have no idea if this is remotely possible, so feel free to close if not!
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Contributor 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
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1532 ·
All issues in python-attrs/attrs
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·