New submission from Michael Shields <mshie...@google.com>: 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. ---------- components: Library (Lib) messages: 118469 nosy: Michael.Shields priority: normal severity: normal status: open title: Regex objects became uncopyable in 2.5 type: behavior versions: Python 2.5, Python 2.6, Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue10076> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com