Add a `default` argument to `operator.attrgetter` and `operator.itemgetter`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
The proposal if for these functions to receive a default argument.
The main motivation is operator.attrgetter, which implements nested attribute access, but is missing getattr's default value support. operator.itemgetter also gets the default argument for consistency.
For operator.attrgetter, only AttributeErrors should be suppressed, and for operator.itemgetter, KeyError.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
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 reviewing the proposed behavior for operator.attrgetter and operator.itemgetter, then read the linked Discourse discussion for unresolved design questions. Trace the existing implementations and tests for both functions; done means supporting a default argument while suppressing only AttributeError for attrgetter and KeyError for itemgetter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100