python-attrs / python-attrs/attrs
More convenient shorthand for derived attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
Resolving #165 allowed setting the default for an attribute based on other attributes using a decorator like this:
@attrs(frozen=True, slots=True)
class Foo:
bar = attr.ib()
moo = attr.ib()
@moo.default
def _init_moo(self):
return self.bar + 2
Many times in frozen classes we want to derive one attribute from another without giving the user the opportunity to override it. The Immutables library for Java provides for this via Value.Derived: http://immutables.github.io/immutable.html#derived-attributes . Perhaps attrs could have a @field.derived decorator which does the same thing?
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 by reading the existing @moo.default decorator behavior and how attrs handles frozen classes. Compare that with the proposed @field.derived entry point and the linked Immutables example. Done means a derived attribute can be calculated from other attributes without allowing the user to override it, with behavior and scope agreed for attrs.
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
- Mostly clear
- Newbie friendliness
- 28/100