[Python-Dev] DRAFT: pydev summary for 2006-12-01 to 2006-12-15
Walter Dörwald
walter at livinglogic.de
Tue Jan 9 14:02:10 CET 2007
Calvin Spealman wrote:
> [...]
> -----------------------------------
> Creating dicts from dict subclasses
> -----------------------------------
>
> A common problem of subclassing built-in types (dict, in this case) arose trying
> to move weakref.WeakValueDictionary to a subclass of dict, rather than UserDict.
>
> [NOTE: Could someone give a better description of this? I don't know enough of
> the issue here to write any content full enough. Thanks.]
The problem is that if you pass a mapping (i.e. something with a keys()
method) to the dict constructor, it uses keys() and __getitem__() to
make a copy. However if the argument is a subclass of dict, any
overwritten keys() or __getitem__() methods are ignored.
Servus,
Walter
More information about the Python-Dev
mailing list