From: Fredrik Lundh Date: Thu, 27 Jun 2002 19:59:27 +0000 (+0000) Subject: Fix bug #570057: Broken pre.subn() (and pre.sub()) X-Git-Tag: v2.3c1~5186 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f7c3431c80b93d0b82e1d1a2d087192f9f9c590;p=python Fix bug #570057: Broken pre.subn() (and pre.sub()) This should be backported to the 2.2.X series (how do I do that?) --- diff --git a/Lib/pre.py b/Lib/pre.py index 504c7c6685..8bbc1001f0 100644 --- a/Lib/pre.py +++ b/Lib/pre.py @@ -367,10 +367,12 @@ class RegexObject: end = len(source) if type(repl) is type(''): - # See if repl contains group references + # See if repl contains group references (if it does, + # pcre_expand will attempt to call _Dummy.group, which + # results in a TypeError) try: repl = pcre_expand(_Dummy, repl) - except error: + except (error, TypeError): m = MatchObject(self, source, 0, end, []) repl = lambda m, repl=repl, expand=pcre_expand: expand(m, repl) else: