python-attrs / python-attrs/attrs
Class variables
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
Every now and then I stumble into wanting to have class variables that are part of everything (e.g. repr) except __init__.
We can do:
@attr.s
class C:
x = attr.ib(default="42", init=False)
but that seems wasteful.
It would be nice to have something like:
@attr.s
class C:
x = attr.ib_class(42)
that just promotes the value into x in class level and adds an Attribute to attrs's bookkeeping.
Opinions?
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 how attr.s and attr.ib handle class attributes, init, repr, and attrs bookkeeping. Define whether the proposed attr.ib_class(42) behavior should promote the value while excluding it from initialization, then use the existing behavior as the basis for tests and acceptance criteria.
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
- 30/100