Skip to content

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

@FFY00

Description

@FFY00

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions