This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients guijarro, gvanrossum, rhettinger
Date 2020-08-28.02:32:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1598581928.91.0.446246774793.issue41647@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-08-28 02:32:08rhettingersetrecipients: + rhettinger, gvanrossum, guijarro
2020-08-28 02:32:08rhettingersetmessageid: <1598581928.91.0.446246774793.issue41647@roundup.psfhosted.org>
2020-08-28 02:32:08rhettingerlinkissue41647 messages
2020-08-28 02:32:08rhettingercreate