]> granicus.if.org Git - python/commitdiff
[3.6] bpo-30605: Fix compiling binary regexs with BytesWarnings enabled. (GH-2016...
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 15 Jun 2017 13:55:22 +0000 (16:55 +0300)
committerGitHub <noreply@github.com>
Thu, 15 Jun 2017 13:55:22 +0000 (16:55 +0300)
Running our unit tests with `-bb` enabled triggered this failure..
(cherry picked from commit 171b9a354e816eebc6d4c3a8553303942e9c5025)

Lib/sre_parse.py
Lib/test/test_re.py
Misc/ACKS
Misc/NEWS

index 608f9a26642f05f3e645a6d0783669b3fedf1d34..b505e11a7eea9103559a6690bbcf1254716e6dbc 100644 (file)
@@ -736,7 +736,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 '',
                                 ),
index e88d0b3dcf2a78a73c0705c42699175757003e2f..a6cbbd0b67abf8868259d4d78d383a14c1717fc8 100644 (file)
@@ -1346,7 +1346,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__)
 
@@ -1355,10 +1355,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):
index c2ebf7faa40a9e85a799698b56c4bd597c76253d..1f3a0cceb274b22afb902984f794388b1a083dd4 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1663,6 +1663,7 @@ Jakub Wilk
 Gerald S. Williams
 Jason Williams
 John Williams
+Roy Williams
 Sue Williams
 Carol Willing
 Steven Willis
index 22f980ce83099c2d8b899176ded5b23a2e5d683d..a258f52e9003ca6ebecd9e5b1c2f4ec37a64c63e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -51,6 +51,9 @@ Core and Builtins
 Library
 -------
 
+- bpo-30605: re.compile() no longer raises a BytesWarning when compiling a
+  bytes instance with misplaced inline modifier.  Patch by Roy Williams.
+
 - [Security] bpo-29591: Update expat copy from 2.1.1 to 2.2.0 to get fixes
   of CVE-2016-0718 and CVE-2016-4472. See
   https://sourceforge.net/p/expat/bugs/537/ for more information.