summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRoy Williams <roy.williams.iii@gmail.com>2017-06-10 05:01:16 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-06-10 05:01:16 (GMT)
commit171b9a354e816eebc6d4c3a8553303942e9c5025 (patch)
treedd1dcb26b3b064b7c0bd08e79771e6193c9c8759 /Lib
parent7445381c606faf20e253da42656db478a4349f8e (diff)
downloadcpython-171b9a354e816eebc6d4c3a8553303942e9c5025.zip
cpython-171b9a354e816eebc6d4c3a8553303942e9c5025.tar.gz
cpython-171b9a354e816eebc6d4c3a8553303942e9c5025.tar.bz2
bpo-30605: Fix compiling binary regexs with BytesWarnings enabled. (#2016)
Running our unit tests with `-bb` enabled triggered this failure.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/sre_parse.py2
-rw-r--r--Lib/test/test_re.py16
2 files changed, 15 insertions, 3 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index d59d642..5452520 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -765,7 +765,7 @@ def _parse(source, state, verbose, nested, first=False):
if not first or subpattern:
import warnings
warnings.warn(
- 'Flags not at the start of the expression %s%s' % (
+ 'Flags not at the start of the expression %r%s' % (
source.string[:20], # truncate long regexes
' (truncated)' if len(source.string) > 20 else '',
),
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 027df40..0ea5a20 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1368,7 +1368,7 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.match(p, lower_char))
self.assertEqual(
str(warns.warnings[0].message),
- 'Flags not at the start of the expression %s' % p
+ 'Flags not at the start of the expression %r' % p
)
self.assertEqual(warns.warnings[0].filename, __file__)
@@ -1377,10 +1377,22 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.match(p, lower_char))
self.assertEqual(
str(warns.warnings[0].message),
- 'Flags not at the start of the expression %s (truncated)' % p[:20]
+ 'Flags not at the start of the expression %r (truncated)' % p[:20]
)
self.assertEqual(warns.warnings[0].filename, __file__)
+ # bpo-30605: Compiling a bytes instance regex was throwing a BytesWarning
+ with warnings.catch_warnings():
+ warnings.simplefilter('error', BytesWarning)
+ p = b'A(?i)'
+ with self.assertWarns(DeprecationWarning) as warns:
+ self.assertTrue(re.match(p, b'a'))
+ self.assertEqual(
+ str(warns.warnings[0].message),
+ 'Flags not at the start of the expression %r' % p
+ )
+ self.assertEqual(warns.warnings[0].filename, __file__)
+
with self.assertWarns(DeprecationWarning):
self.assertTrue(re.match('(?s).(?i)' + upper_char, '\n' + lower_char))
with self.assertWarns(DeprecationWarning):