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 Michael.Shields
Recipients Michael.Shields
Date 2010-10-12.20:45:22
SpamBayes Score 1.354018e-10
Marked as misclassified No
Message-id <1286916324.24.0.772801528988.issue10076@psf.upfronthosting.co.za>
In-reply-to
Content
For many years now, the sre module has provided __copy__ and __deepcopy__ modules that raise an exception ("cannot copy this pattern object") by default, with an #ifdef to enable their implementations.  Until Python 2.5, these were simply unused.  Since then, deepcopying these objects fails, instead of falling back to the default implementation.

Python 2.4.6 (#1, Nov 23 2009, 03:28:22)
[GCC 4.2.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> x = [re.compile('.*')]
>>> import copy
>>> copy.deepcopy(x)
[<_sre.SRE_Pattern object at 0x7f3e9411e168>]

Python 2.6.2 (r262:71600, Jul 24 2009, 17:29:21)
[GCC 4.2.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> x = [re.compile('.*')]
>>> import copy
>>> copy.deepcopy(x)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/grte/v1/k8-linux/lib/python2.6/copy.py", line 162, in deepcopy
   y = copier(x, memo)
 File "/usr/grte/v1/k8-linux/lib/python2.6/copy.py", line 228, in _deepcopy_list
   y.append(deepcopy(a, memo))
 File "/usr/grte/v1/k8-linux/lib/python2.6/copy.py", line 173, in deepcopy
   y = copier(memo)
TypeError: cannot deepcopy this pattern object

I'll attach a patch against 2.7 to correct this.
History
Date User Action Args
2010-10-12 20:45:24Michael.Shieldssetrecipients: + Michael.Shields
2010-10-12 20:45:24Michael.Shieldssetmessageid: <1286916324.24.0.772801528988.issue10076@psf.upfronthosting.co.za>
2010-10-12 20:45:22Michael.Shieldslinkissue10076 messages
2010-10-12 20:45:22Michael.Shieldscreate