On Feb 10, 2008 8:02 PM, Phillip J. Eby <<a href="mailto:pje@telecommunity.com">pje@telecommunity.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
However, since existing code has to be migrated, and lots of things<br>have copy() methods, and 2to3 isn't going to be able to tell,<br>practicality (IMO) seems to favor keeping the existing method.<br></blockquote></div>
<br>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.<br>
<br>Suggested 2to3 operation:<br><br>foo.copy() => copy(foo)<br>def copy(self): => def __copy__(self): (if within a class definition)<br><br>If __copy__(self) is just "self.copy()", remove it.<br>If copy(self) is just "self.__copy__()" or "copy.copy(self)", remove it<br>
If a class still defines both __copy__ and copy(), print a warning/error (this should be rare).<br><br>If copy is called with arguments or defined with more than the "self" argument, make no change.<br>If copy is defined with more than the "self" argument, but all the arguments are optional, print a warning/error.<br clear="all">
<br>-- <br>Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises LLC