[Python-checkins] [3.9] bpo-41520: Fix second codeop regression (GH-21848)

Miss Islington (bot) webhook-mailer at python.org
Thu Aug 13 14:39:04 EDT 2020


https://github.com/python/cpython/commit/a3416c13b51af25675e175d4ffe07d8b925e7dbf
commit: a3416c13b51af25675e175d4ffe07d8b925e7dbf
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-08-13T11:38:55-07:00
summary:

[3.9] bpo-41520: Fix second codeop regression (GH-21848)


Fix the repression introduced by the initial regression fix.

(cherry picked from commit c818b15fa59039de67022c29085d439fa5d3ef95)
Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>
(cherry picked from commit f24430f1542ea2768793b48704ae2d4e241892ae)

Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>

files:
M Lib/codeop.py
M Lib/test/test_codeop.py
M Misc/NEWS.d/next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst

diff --git a/Lib/codeop.py b/Lib/codeop.py
index 97043877d1869..04ca6b9317087 100644
--- a/Lib/codeop.py
+++ b/Lib/codeop.py
@@ -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)
diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py
index 1eae26b6ce17e..01ee00c3b4c91 100644
--- a/Lib/test/test_codeop.py
+++ b/Lib/test/test_codeop.py
@@ -297,14 +297,17 @@ def test_filename(self):
 
     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__":
diff --git a/Misc/NEWS.d/next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst b/Misc/NEWS.d/next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst
index ca5501c2aeec0..0e140d91bb4b6 100644
--- a/Misc/NEWS.d/next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst
+++ b/Misc/NEWS.d/next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst
@@ -1 +1 @@
-Fix :mod:`codeop` regression: it no longer ignores :exc:`SyntaxWarning`.
+Fix :mod:`codeop` regression that prevented turning compile warnings into errors.



More information about the Python-checkins mailing list