[Python-3000] Nix dict.copy()
daniel at stutzbachenterprises.com
Tue Feb 12 23:40:10 CET 2008
On Feb 12, 2008 11:56 AM, Guido van Rossum <guido at python.org> wrote:
> Here's another way to look at it, maybe it'll help. My hunch is that
> whenever someone writes x = copy(y), they actually know more about the
> type of y than just that it is an object! Because if they knew
> *nothing* about it, they wouldn't know whether copying was (a)
> pointless (as it is for immutable objects), (b) impossible (e.g. for
> sockets), or (c) useful (e.g. for lists).
Based on the same reasoning, when we see x = copy(y) we can tentatively
assume that y is a type that can usefully be copied. Unless we don't trust
the author of the code to be sensible.
> Seeing x=copy(y) provides no new information about y, since
> all (well, most) objects can be copied. OTOH seeing x=y.copy() *does*
> provide new information about y; it must be a type that has a .copy()
What useful information do we get by knowing that a type has a .copy()
If I took the last sentence out of context, I would assume that having a
.copy() method informs you that the type is copyable. Except you've just
said that all (well, most) objects in Python can be copied--so I'm not sure
new information a .copy() method conveys.
Normally I might assume that it does a special kind of copying that doesn't
fit the definition of copy.copy() nor copy.deepcopy(), except that for dict
and set types, .copy() and .__copy__() are identical.
Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises LLC
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-3000