[New-bugs-announce] [issue11480] Cannot copy a class with a metaclass other than type

Daniel Urban report at bugs.python.org
Sun Mar 13 10:04:20 CET 2011


New submission from Daniel Urban <urban.dani+py at gmail.com>:

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).

----------
components: Library (Lib)
files: copy_metaclass.patch
keywords: patch
messages: 130731
nosy: durban
priority: normal
severity: normal
status: open
title: Cannot copy a class with a metaclass other than type
type: behavior
versions: Python 3.1, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file21100/copy_metaclass.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11480>
_______________________________________


More information about the New-bugs-announce mailing list