summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/codeop.py4
-rw-r--r--Lib/test/test_codeop.py13
-rw-r--r--Misc/NEWS.d/next/Library/2020-08-12-13-25-16.bpo-41520.BEUWa4.rst2
3 files changed, 11 insertions, 8 deletions
diff --git a/Lib/codeop.py b/Lib/codeop.py
index 547629262d..4c10470aee 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 7984e5f1e5..45d0a7de9d 100644
--- a/Lib/test/test_codeop.py
+++ b/Lib/test/test_codeop.py
@@ -307,14 +307,17 @@ class CodeopTests(unittest.TestCase):
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):
+ 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 ca5501c2ae..0e140d91bb 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.