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

Robert Brewer fumanchu at amor.org
Mon Jul 9 23:55:41 CEST 2007


Raymond Hettinger wrote:
> > PEP 3100 suggests dict.setdefault() may be removed in 
> > Python 3, since it is in principle no longer necessary
> > (due to the new defaultdict type).
> 
> I've forgotten.  What was the whole point of Python 3.0?
> Is it to make the language fat with lots of ways to do everything?
> Guys, this is your ONE chance to slim down the language and
> pare away anything that is unnecessary or arcane.
> 
> The setdefault() method has too many defects to keep around.
> Why would you want a method that instantiates the default on
> every call even if not needed.  
> 
> Let this one die.  The dict API already heavily loaded.  Thinning
> it a bit would be a nice improvement.

I have to agree, even though it means more work for me (due to my own
heavy use of setdefault for its atomicity). Perhaps a better resolution
for these use cases would be a stdlib module which would provide fast,
thread-safe collections. This would standardize, across implementations,
some of the CPython behaviors we've come to rely on. It would also make
make it clear that the given type is being used specifically for its
thread-safety.


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org


More information about the Python-3000 mailing list