[Python-3000] A request to keep dict.setdefault() in 3.0

Phillip J. Eby pje at telecommunity.com
Tue Jul 10 02:21:44 CEST 2007


At 12:04 AM 7/10/2007 +0300, Guido van Rossum wrote:
>On 7/9/07, Barry Warsaw <barry at python.org> wrote:
>>Phillip, I support any initiative to keep .setdefault() or similar
>>functionality.  When this thread came up before, I wasn't against
>>defaultdict, I just didn't think it covered enough of the use cases
>>of .setdefault() to warrant its removal.  You describe some
>>additional use cases.
>>
>>However, .setdefault() is a horrible name because it's not clear from
>>the name that a 'get' operation also happens.
>
>We had a long name discussion when it was introduced. Perhaps we can
>go back to the list suggested then and see if a better alternative was
>overlooked?

Personally, for my use cases it wouldn't matter if it didn't return a 
value, because I'm not using it to shorten the code.  So if you took 
away the return value and left the name (or changed it to something 
clearer), that'd be okay by me.

The alternative, of course, is as Robert suggested, to just write 
some library code to deal with this and similar issues.  If I have to 
import setdefault from somewhere to use it (ala the heapq.* 
functions), that's fine by me too, as long as it's still able to be 
atomic.  That approach might also address Raymond's desire to narrow 
the dictionary object API.



More information about the Python-3000 mailing list