diff -r e948154af406 Lib/sre_parse.py --- a/Lib/sre_parse.py Sat Apr 13 18:00:04 2013 +0300 +++ b/Lib/sre_parse.py Sat Apr 13 12:01:09 2013 -0400 @@ -588,7 +588,7 @@ if not name: raise error("missing group name") if not isname(name): - raise error("bad character in group name") + raise error("bad character in group name %r" % name) elif sourcematch("="): # named backreference name = "" @@ -602,7 +602,8 @@ if not name: raise error("missing group name") if not isname(name): - raise error("bad character in group name") + raise error("bad character in backref group name " + "%r" % name) gid = state.groupdict.get(name) if gid is None: raise error("unknown group name") diff -r e948154af406 Lib/test/test_re.py --- a/Lib/test/test_re.py Sat Apr 13 18:00:04 2013 +0300 +++ b/Lib/test/test_re.py Sat Apr 13 12:01:09 2013 -0400 @@ -3,6 +3,7 @@ import io import re from re import Scanner +import sre_constants import sys import string import traceback @@ -1021,6 +1022,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, ''): + re.compile('(?P=)') + + 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)') + def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR diff -r e948154af406 Misc/ACKS --- a/Misc/ACKS Sat Apr 13 18:00:04 2013 +0300 +++ b/Misc/ACKS Sat Apr 13 12:01:09 2013 -0400 @@ -805,6 +805,7 @@ Alexis Métaireau Steven Miale Trent Mick +Jason Michalski Franck Michea Tom Middleton Stan Mihai