Issue #27030: Unknown escapes in re.sub() replacement template are allowed
again. But they still are deprecated and will be disabled in 3.7.
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index ab37fd3..6aa49c3 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -947,7 +947,9 @@
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 --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 84131d2..4bdaa4b 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -126,7 +126,7 @@
(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')