Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a default argument to operator.attrgetter and operator.itemgetter #129305

Open
FFY00 opened this issue Jan 26, 2025 · 1 comment
Open

Add a default argument to operator.attrgetter and operator.itemgetter #129305

FFY00 opened this issue Jan 26, 2025 · 1 comment
Labels
extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@FFY00
Copy link
Member

FFY00 commented Jan 26, 2025

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:

https://discuss.python.org/t/enhancing-getattr-to-support-nested-attribute-access-with-dotted-strings/74305/12

@FFY00 FFY00 added the type-feature A feature request or enhancement label Jan 26, 2025
@sobolevn
Copy link
Member

There's a recent PEP about that: python/steering-council#269

@picnixz picnixz added stdlib Python modules in the Lib dir extension-modules C modules in the Modules dir labels Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants