Add a default
argument to operator.attrgetter
and operator.itemgetter
#129305
Labels
extension-modules
C modules in the Modules dir
stdlib
Python modules in the Lib dir
type-feature
A feature request or enhancement
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 missinggetattr
's default value support.operator.itemgetter
also gets thedefault
argument for consistency.For
operator.attrgetter
, onlyAttributeError
s should be suppressed, and foroperator.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
The text was updated successfully, but these errors were encountered: