]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-41520: Fix second codeop regression (GH-21848)
authorTerry Jan Reedy <tjreedy@udel.edu>
Thu, 13 Aug 2020 18:21:32 +0000 (14:21 -0400)
committerGitHub <noreply@github.com>
Thu, 13 Aug 2020 18:21:32 +0000 (14:21 -0400)
Fix the repression introduced by the initial regression fix.

(cherry picked from commit c818b15fa59039de67022c29085d439fa5d3ef95)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Lib/codeop.py
Lib/test/test_codeop.py
Misc/NEWS.d/next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst

index 547629262d06892cd36d7423403d849691b676bf..4c10470aee7b7c1db059a29dd95b02157305fa7f 100644 (file)
@@ -85,9 +85,9 @@ def _maybe_compile(compiler, source, filename, symbol):
         pass
 
     # Catch syntax warnings after the first compile
-    # to emit SyntaxWarning at most once.
+    # to emit warnings (SyntaxWarning, DeprecationWarning) at most once.
     with warnings.catch_warnings():
-        warnings.simplefilter("error", SyntaxWarning)
+        warnings.simplefilter("error")
 
         try:
             code1 = compiler(source + "\n", filename, symbol)
index 72840cae1d9e983e07a019b3c1e4e9fa851e7881..66caf5aaae32b978beaf4f820bc648406bfc8786 100644 (file)
@@ -306,14 +306,17 @@ class CodeopTests(unittest.TestCase):
 
     def test_warning(self):
         # Test that the warning is only returned once.
-        with support.check_warnings((".*literal", SyntaxWarning)) as w:
-            compile_command("0 is 0")
-            self.assertEqual(len(w.warnings), 1)
+        with support.check_warnings(
+                (".*literal", SyntaxWarning),
+                (".*invalid", DeprecationWarning),
+                ) as w:
+            compile_command(r"'\e' is 0")
+            self.assertEqual(len(w.warnings), 2)
 
         # bpo-41520: check SyntaxWarning treated as an SyntaxError
-        with self.assertRaises(SyntaxError):
+        with warnings.catch_warnings(), self.assertRaises(SyntaxError):
             warnings.simplefilter('error', SyntaxWarning)
-            compile_command('1 is 1\n', symbol='exec')
+            compile_command('1 is 1', symbol='exec')
 
 
 if __name__ == "__main__":
index ca5501c2aeec0de8dc7476ecb8b7ef15ddd6e8e4..0e140d91bb4b61cb2ecf8ea0b96cfb67775ff5e8 100644 (file)
@@ -1 +1 @@
-Fix :mod:`codeop` regression: it no longer ignores :exc:`SyntaxWarning`.
+Fix :mod:`codeop` regression that prevented turning compile warnings into errors.