diff -r ab66423c3581 Doc/library/re.rst --- a/Doc/library/re.rst Mon Dec 05 22:31:12 2016 -0800 +++ b/Doc/library/re.rst Tue Dec 06 12:16:42 2016 +0200 @@ -758,7 +758,12 @@ form. Unmatched groups are replaced with an empty string. .. versionchanged:: 3.6 - Unknown escapes consisting of ``'\'`` and an ASCII letter now are errors. + Unknown escapes in *pattern* consisting of ``'\'`` and an ASCII letter + now are errors. + + .. deprecated-removed:: 3.5 3.7 + Unknown escapes in *repl* consist of ``'\'`` and ASCII letter now raise + a deprecation warning and will be forbidden in Python 3.7. .. function:: subn(pattern, repl, string, count=0, flags=0) diff -r ab66423c3581 Lib/sre_parse.py --- a/Lib/sre_parse.py Mon Dec 05 22:31:12 2016 -0800 +++ b/Lib/sre_parse.py Tue Dec 06 12:16:42 2016 +0200 @@ -947,7 +947,9 @@ def parse_template(source, pattern): this = chr(ESCAPES[this][1]) except KeyError: if c in ASCIILETTERS: - raise s.error('bad escape %s' % this, len(this)) + import warnings + warnings.warn('bad escape %s' % this, + DeprecationWarning, stacklevel=4) lappend(this) else: lappend(this) diff -r ab66423c3581 Lib/test/test_re.py --- a/Lib/test/test_re.py Mon Dec 05 22:31:12 2016 -0800 +++ b/Lib/test/test_re.py Tue Dec 06 12:16:42 2016 +0200 @@ -126,7 +126,7 @@ class ReTests(unittest.TestCase): (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)+chr(8))) for c in 'cdehijklmopqsuwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ': with self.subTest(c): - with self.assertRaises(re.error): + with self.assertWarns(DeprecationWarning): self.assertEqual(re.sub('a', '\\' + c, 'a'), '\\' + c) self.assertEqual(re.sub(r'^\s*', 'X', 'test'), 'Xtest') diff -r ab66423c3581 Misc/NEWS --- a/Misc/NEWS Mon Dec 05 22:31:12 2016 -0800 +++ b/Misc/NEWS Tue Dec 06 12:16:42 2016 +0200 @@ -26,6 +26,9 @@ Core and Builtins Library ------- +- Issue #28450: Unknown escapes in re.sub() replacement template template are + allowed again. But they still are deprecated and will be disabled in 3.7. + - Issue #27172: To assist with upgrades from 2.7, the previously documented deprecation of ``inspect.getfullargspec()`` has been reversed. This decision may be revisited again after the Python 2.7 branch is no longer officially