[Anthony Baxter] >> Ok, so here's the state of play: 2.3.5 is currently aimed for next >> Tuesday, but there's an outstanding issue - the new copy code appears >> to have broken something, see www.python.org/sf/1114776 for the gory >> details. ...
[Alex Martelli] > The problem boils down to: deepcopying an instance of a type that > doesn't have an __mro__ (and is not one of the many types explicitly > recorded in the _deepcopy_dispatch dictionary, such as types.ClassType, > types.InstanceType, etc, etc). > > The easy fix: instead of cls.__mro__ use inspect.getmro which deals > with that specifically. > > Before I commit the fix: can anybody help out with an example of a type > anywhere in the standard library that should be deepcopyable, used to > be deepcopyable in 2.3.4, isn't one of those which get explicitly > recorded in copy._deepcopy_dispatch, AND doesn't have an __mro__? Even > the _testcapi.Copyable type magically grows an __mro__; I'm not sure > how to MAKE a type w/o one... Since the original bug report came from Zopeland, chances are good (although the report is too vague to be sure) that the problem involves ExtensionClass. That's complicated C code in Zope predating new-style classes, making it possible to build Python-class-like objects in C code under old Pythons. In general, EC-derived classes don't play well with newer Python features (well, at least not until Zope 2.8, where ExtensionClass is recoded as a new-style Python class -- but still keeping some semantics from old-style classes ... ). Anyway, I expect that instances of any EC-derived class would have the problem in the bug report. For example, the base Persistent class in ZODB 3.2.5 is an ExtensionClass: $ \python23\python.exe Python 2.3.5c1 (#61, Jan 25 2005, 19:52:06) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import ZODB # don't ask -- it's necessary to import this first >>> from Persistence import Persistent >>> p = Persistent() >>> import copy >>> copy.deepcopy(p) # deepcopy() barfs on __mro__ Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python23\lib\copy.py", line 200, in deepcopy copier = _getspecial(cls, "__deepcopy__") File "C:\Python23\lib\copy.py", line 66, in _getspecial for basecls in cls.__mro__: AttributeError: __mro__ >>> copy.copy(p) # copy() does too Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python23\lib\copy.py", line 86, in copy copier = _getspecial(cls, "__copy__") File "C:\Python23\lib\copy.py", line 66, in _getspecial for basecls in cls.__mro__: AttributeError: __mro__ Unsure whether this is enough, but at least inspect.getmro() isn't phased by an EC-derived class: >>> inspect.getmro(Persistent) (<extension class Persistence.Persistent at 100040D8>,) More info from the bug report filer is really needed. A problem is that this stuff doesn't appear "to work" under Python 2.3.4 either: $ ../Python-2.3.4/python Python 2.3.4 (#1, Aug 9 2004, 17:15:36) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ZODB >>> from Persistence import Persistent >>> p = Persistent() >>> import copy >>> copy.deepcopy(p) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/tim/Python-2.3.4/Lib/copy.py", line 206, in deepcopy y = _reconstruct(x, rv, 1, memo) File "/home/tim/Python-2.3.4/Lib/copy.py", line 338, in _reconstruct y = callable(*args) TypeError: ExtensionClass object argument after * must be a sequence >>> copy.copy(p) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/home/tim/Python-2.3.4/Lib/copy.py", line 95, in copy return _reconstruct(x, rv, 0) File "/home/tim/Python-2.3.4/Lib/copy.py", line 338, in _reconstruct y = callable(*args) TypeError: ExtensionClass object argument after * must be a sequence >>> _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com