[New-bugs-announce] [issue41647] MutableMapping ".setdefault()" to return default value via __getitem__

Matias G report at bugs.python.org
Thu Aug 27 06:28:20 EDT 2020


New submission from Matias G <guijarro at esrf.fr>:

Hi,

This is more a question/proposal than a real issue. I apologize in
advance if this has already been debated or if it is not relevant.

I noticed `setdefault` method of mutable mapping objects is returning
the default value as passed in the call, when applicable, without
passing through `__getitem__`.

I think it would be more "symmetric" if it would return the default
value set by `__setitem__` via `__getitem__`. This would handle the
case of a custom MutableMapping defining a custom behaviour of
`__setitem__` and `__getitem__`.

Of course, in my case finally I overloaded `setdefault` to do this,
but it might be worth in general, at least for the MutableMapping
class.

Thanks,
Matias.

----------
messages: 375984
nosy: guijarro
priority: normal
severity: normal
status: open
title: MutableMapping ".setdefault()" to return default value via __getitem__
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41647>
_______________________________________


More information about the New-bugs-announce mailing list