python-attrs / python-attrs/attrs
Support abstract functionality for attrs classes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
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!
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.
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.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100