Message376015
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. |
|
Date |
User |
Action |
Args |
2020-08-28 02:32:08 | rhettinger | set | recipients:
+ rhettinger, gvanrossum, guijarro |
2020-08-28 02:32:08 | rhettinger | set | messageid: <1598581928.91.0.446246774793.issue41647@roundup.psfhosted.org> |
2020-08-28 02:32:08 | rhettinger | link | issue41647 messages |
2020-08-28 02:32:08 | rhettinger | create | |
|