[Python-3000] Nix dict.copy()

Raymond Hettinger python at rcn.com
Sun Feb 10 22:10:48 CET 2008


>> [Phillip Eby]
>>> I'm not fond of this idea. dict.copy() is polymorphic -- but dict(d) is...

[Raymond]
>> Can't say dict.copy() is really polymorphic if only one other class defines the method.

[Martin]
> Why do you say it's only one? I found atleast UserDict.copy, os._Environ.copy, WeakValueDictionary.copy, WeakKeyDictionary.copy,

It would have been better for me to say that copy() seems to appear only in variants of dicts, but __copy__() is a long-standing 
defined protocol that is supported across non-mapping types as well.

Underneath the hood, __copy__() and copy() have the same implementation, so it's really a question of whether we want two ways to 
say the same thing (with one of those ways being polymorphic across many objects and the other being used mainly for dict variants).

Had copy() been a builtin, we probably wouldn't be having this discussion.


Raymond


More information about the Python-3000 mailing list