Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

The current code makes sense to me and also mirrors the actual implementation 
of setdefault() for regular dictionaries. 

While I can see what you're trying do, it is a feature that __getitem__() is 
not called.  And for regular dicts, that is the only way to make it an atomic 
operation.

In any case, the proposal would be a behavior change that breaks code — users 
are likely and justifiably relying on the actual default value being returned 
rather than a possibly new value computed by the __getitem__() method.

There is also an efficiency concern.  Changing the behavior implies that 
missing keys would trigger one initial search, then a store for the default, 
and then another subsequent lookup.  Speaking only for myself, I know that I 
would never want that by default.  If required, I would prefer to override 
setdefault() and explicitly spell-out the new behavior.

----------
nosy: +gvanrossum

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41647>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to