[issue31240] Add lazy evaluation support for dict.setdefault()

2017-08-20 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python

[issue31240] Add lazy evaluation support for dict.setdefault()

2017-08-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 from me as well. The need has already been fulfilled in other ways (defaultdict and __missing__). I don't think we need yet another way to do it. Also, I suspect that the benefit of a lazy instantiation would be more than offset by cost of passing in t

[issue31240] Add lazy evaluation support for dict.setdefault()

2017-08-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The advantage of dict.setdefault() is its atomicity. With lazy evaluation of the value it can't be atomic anymore, and can be replaced with the following code: if key not in mydict: mydict[key] = value I'm -1 for this change. It increases comple

[issue31240] Add lazy evaluation support for dict.setdefault()

2017-08-19 Thread Jim Dennis
New submission from Jim Dennis: Code such as mydict.setdefault('eggs', []) will needlessly incur the cost of instantiating a list even when 'eggs' is already a valid key in mydict. collections.defaultdict will not do this. detecting and automatically calling "callable" and "type" objects (im