Skip to content

Commit f24430f

Browse files
authored
[3.9] bpo-41520: Fix second codeop regression (GH-21848)
Fix the repression introduced by the initial regression fix. (cherry picked from commit c818b15) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent b3ad2ca commit f24430f

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Lib/codeop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def _maybe_compile(compiler, source, filename, symbol):
8585
pass
8686

8787
# Catch syntax warnings after the first compile
88-
# to emit SyntaxWarning at most once.
88+
# to emit warnings (SyntaxWarning, DeprecationWarning) at most once.
8989
with warnings.catch_warnings():
90-
warnings.simplefilter("error", SyntaxWarning)
90+
warnings.simplefilter("error")
9191

9292
try:
9393
code1 = compiler(source + "\n", filename, symbol)

Lib/test/test_codeop.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,17 @@ def test_filename(self):
306306

307307
def test_warning(self):
308308
# Test that the warning is only returned once.
309-
with support.check_warnings((".*literal", SyntaxWarning)) as w:
310-
compile_command("0 is 0")
311-
self.assertEqual(len(w.warnings), 1)
309+
with support.check_warnings(
310+
(".*literal", SyntaxWarning),
311+
(".*invalid", DeprecationWarning),
312+
) as w:
313+
compile_command(r"'\e' is 0")
314+
self.assertEqual(len(w.warnings), 2)
312315

313316
# bpo-41520: check SyntaxWarning treated as an SyntaxError
314-
with self.assertRaises(SyntaxError):
317+
with warnings.catch_warnings(), self.assertRaises(SyntaxError):
315318
warnings.simplefilter('error', SyntaxWarning)
316-
compile_command('1 is 1\n', symbol='exec')
319+
compile_command('1 is 1', symbol='exec')
317320

318321

319322
if __name__ == "__main__":
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix :mod:`codeop` regression: it no longer ignores :exc:`SyntaxWarning`.
1+
Fix :mod:`codeop` regression that prevented turning compile warnings into errors.

0 commit comments

Comments
 (0)