[Python-Dev] copy confusion (original) (raw)
Guido van Rossum gvanrossum at gmail.com
Wed Jan 12 05:11:16 CET 2005
- Previous message: [Python-Dev] copy confusion
- Next message: getting special from type, not instance (was Re: [Python-Dev] copy confusion)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Unfortunately, we do have a problem with the code in copy.py:
class MetaCopyableClass(type): def copy(cls): """ code to copy CLASSES of this metaclass """ # etc, etc, snipped class CopyableClass: metaclass = MetaCopyableClass # rest of class snipped x = CopyableClass() import copy y = copy.copy(x) kallisti:/tmp alex$ python x.py Traceback (most recent call last): File "x.py", line 14, in ? y = copy.copy(x) File "/usr/local/lib/python2.4/copy.py", line 79, in copy return copier(x) TypeError: copy() takes exactly 1 argument (2 given) kallisti:/tmp alex$ See? copy.copy(x) ends up using MetaCopyableClass.copy -- because of a getattr on CopyableClass for 'copy', which gets the BOUND-METHOD defined in the metaclass, with imself being CopyableClass. I had exactly the same metabug in the pep 246 reference implementation, Armin Rigo showed how to fix it in his only recent post.
Don't recall seeing that, but if you or he can fix this without breaking other stuff, it's clear you should go ahead. (This worked in 2.2, FWIW; it broke in 2.3.)
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] copy confusion
- Next message: getting special from type, not instance (was Re: [Python-Dev] copy confusion)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]