Dict can't update with dict-like objects 
Author Message
 Dict can't update with dict-like objects

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?

-Chuck
--
http://www.*-*-*.com/

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 10 Feb 2003 11:48:50 GMT  
 Dict can't update with dict-like objects

Quote:

> 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/)



Mon, 10 Feb 2003 12:49:03 GMT  
 Dict can't update with dict-like objects

Quote:
> 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).

Could you please make another mental note (or expand the first one)
for eval()?

Thanks, Frank
--
"Ford!" he said, "there's an infinite number of monkeys outside who want to
talk to us about this script for Hamlet they've worked out."
        -- Douglas Adams, 'The Hitch Hiker's Guide to the Galaxy'



Mon, 10 Feb 2003 03:00:00 GMT  
 Dict can't update with dict-like objects


    [snip]

Quote:
> 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).

Excellent game-plan!  Might we humbly request an *explicit* list of
"such restrictions" that are currently known to exist but intended
to be eventually removed...?  Mental notes are OK, but an explicit
todo-list will help in several ways, I think.

Alex



Mon, 10 Feb 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. expanding a list and dict to a *args and **dict

2. NewBuiltins: added dict() -- inverse of dict.items()

3. Builtin dict should be callable, since a dict defines a funct ion

4. Builtin dict should be callable, since a dict defines a function

5. Dict to String and String to Dict with Visual Works

6. Recursive update of arbitrarily nested dicts

7. enhancing dictionary update method and the dict type constructor

8. dict tuple update

9. class object vs. dict

10. Are strings copied when passed to a regex object if a dict lookup

11. copy-on-write for dict objects?

12. Request: module that converts iis Request module to Dict like object

 

 
Powered by phpBB® Forum Software