This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author daniel.urban
Recipients daniel.urban
Date 2011-03-13.09:04:18
SpamBayes Score 1.1022849e-12
Marked as misclassified No
Message-id <1300007060.0.0.461224143225.issue11480@psf.upfronthosting.co.za>
In-reply-to
Content
copy.copy cannot copy a class which have a metaclass other than type:

>>> import abc
>>> import copy
>>> 
>>> class C(metaclass=abc.ABCMeta):
...     pass
... 
>>> copy.copy(C)
Traceback (most recent call last):
    ...
TypeError: can't pickle int objects


The reason seems to be, as described in msg8329 (issue494904) that the __reduce_ex__ function inherited from object will be called instead of the method bound to the class object (that's the reason of the strange error message). (See also issue7689.)

The interesting thing is, that copy.deepcopy was already fixed in 4680ef4fe90a.  I'm attaching a patch, that does basically the same for copy that was done with deepcopy (it also includes a test).
History
Date User Action Args
2011-03-13 09:04:20daniel.urbansetrecipients: + daniel.urban
2011-03-13 09:04:19daniel.urbansetmessageid: <1300007060.0.0.461224143225.issue11480@psf.upfronthosting.co.za>
2011-03-13 09:04:19daniel.urbanlinkissue11480 messages
2011-03-13 09:04:19daniel.urbancreate