#17341: Include name in re error message about invalid group name.
Patch by Jason Michalski.
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 6ddddda..18a81a2 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -2,6 +2,7 @@
from test.test_support import precisionbigmemtest, _2G, cpython_only
import re
from re import Scanner
+import sre_constants
import sys
import string
import traceback
@@ -886,6 +887,16 @@
self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT)
self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT)
+ def test_backref_group_name_in_exception(self):
+ # Issue 17341: Poor error message when compiling invalid regex
+ with self.assertRaisesRegexp(sre_constants.error, '<foo>'):
+ re.compile('(?P=<foo>)')
+
+ def test_group_name_in_exception(self):
+ # Issue 17341: Poor error message when compiling invalid regex
+ with self.assertRaisesRegexp(sre_constants.error, '\?foo'):
+ re.compile('(?P<?foo>)')
+
def run_re_tests():
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR