python-attrs / python-attrs/attrs
Conditional initialization of attributes
Open
Nobody has claimed this yet.
Feature
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 2
Description
While trying to use attrs with sqlalchemy, I came across an issue that in some cases it's needed to initialize an attribute only if it was passed to constructor.
Basically, this code
@attr.attrs
class A:
a = attr.ib(initialize_if_given=True)
should translate to this
CONDITIONAL_INIT = object()
class A:
def __init__(a=CONDITIONAL_INIT):
if a is not CONDITIONAL_INIT:
self.a = a
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
No file, test, or entry point is named in the issue. Start from the two constructor examples and review the project's existing initialization behavior; done means supporting conditional attribute assignment when the argument is provided while preserving current constructor behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100