From 450ede437011622773c4f8064e6313e0aa65d25f Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 12 Aug 2020 13:40:46 -0400 Subject: [PATCH 1/4] bpo-41520: Fix second codeop repression Fix the repression introduced by the initial regression fix. --- Lib/codeop.py | 2 +- Lib/test/test_codeop.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Lib/codeop.py b/Lib/codeop.py index 547629262d0689..e169f3ff99340d 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -87,7 +87,7 @@ def _maybe_compile(compiler, source, filename, symbol): # Catch syntax warnings after the first compile # to emit SyntaxWarning 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 7984e5f1e5a69a..0340a5a0c4f502 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -307,14 +307,17 @@ def test_filename(self): def test_warning(self): # Test that the warning is only returned once. - with warnings_helper.check_warnings((".*literal", SyntaxWarning)) as w: - compile_command("0 is 0") - self.assertEqual(len(w.warnings), 1) + with warnings_helper.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): warnings.simplefilter('error', SyntaxWarning) - compile_command('1 is 1\n', symbol='exec') + compile_command('1 is 1', symbol='exec') if __name__ == "__main__": From bb43d3e7026151c1837d44caf2b44f1aaacf536f Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 12 Aug 2020 13:46:53 -0400 Subject: [PATCH 2/4] Fix news. --- .../next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ca5501c2aeec0d..0e140d91bb4b61 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. From 409f46c053a62ea3a3eeb0c74a5fc332f7eed5ec Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 12 Aug 2020 14:16:51 -0400 Subject: [PATCH 3/4] Don't alter the execution environment. --- Lib/test/test_codeop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index 0340a5a0c4f502..45d0a7de9d9253 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -315,7 +315,7 @@ def test_warning(self): 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', symbol='exec') From 09af3f519e871aeb1b111e24813d5448807eb46a Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 12 Aug 2020 17:38:34 -0400 Subject: [PATCH 4/4] Update Lib/codeop.py Co-authored-by: Victor Stinner --- Lib/codeop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/codeop.py b/Lib/codeop.py index e169f3ff99340d..4c10470aee7b7c 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -85,7 +85,7 @@ 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")