Dict can't update with dict-like objects

Guido van Rossum guido at beopen.com
Thu Aug 24 00:49:03 EDT 2000


echuck3 at my-deja.com writes:

> I'm sure this road has been traveled before, but a quick search of the
> FAQ and 1.6 rel notes didn't reveal anything, so here we go:
> 
> ---
> from UserDict import UserDict
> d1 = {}
> d2 = UserDict()
> d1.update(d2)
> ---
> 
> This fails because dictionary's update() doesn't want anything that
> responds like a dictionary, but a bona fide dictionary.
> 
> And, yeah, I'm sure this is for speed, BUT...is there any known
> intention of either changing this, or providing an updateObj() that
> would be more friendly?

It is my intention to *eventually* remove all such restrictions.  This
goes slowly because it has to be done one operation at a time.
E.g. somewhere aling 1.5.x, (a,b,c) = [1,2,3] became legal.  In 2.0,
[].extend(UserList()) will be legal.  I'll make a mental note that
{}.update() needs to be expanded too.  A separate method name is quite
unnecessary (the update() function can simply branch on the argument
type).

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)



More information about the Python-list mailing list