[Python-3000] Nix dict.copy()

Daniel Stutzbach daniel at stutzbachenterprises.com
Mon Feb 11 03:38:34 CET 2008


On Feb 10, 2008 8:02 PM, Phillip J. Eby <pje at telecommunity.com> wrote:

> However, since existing code has to be migrated, and lots of things
> have copy() methods, and 2to3 isn't going to be able to tell,
> practicality (IMO) seems to favor keeping the existing method.
>

If it only converts dict and set .copy() methods, 2to3 can't tell, but it
wouldn't be too hard to respell all instances of foo.copy() as copy(foo).
Obviously, this is a bit more radical and has good and bad points.  It'd be
giving every class's .copy method a promotion to __copy__, basically.

Suggested 2to3 operation:

foo.copy() => copy(foo)
def copy(self):    =>  def __copy__(self):     (if within a class
definition)

If __copy__(self) is just "self.copy()", remove it.
If copy(self) is just "self.__copy__()" or "copy.copy(self)", remove it
If a class still defines both __copy__ and copy(), print a warning/error
(this should be rare).

If copy is called with arguments or defined with more than the "self"
argument, make no change.
If copy is defined with more than the "self" argument, but all the arguments
are optional, print a warning/error.

-- 
Daniel Stutzbach, Ph.D.             President, Stutzbach Enterprises LLC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20080210/f4ff421b/attachment-0001.htm 


More information about the Python-3000 mailing list