Skip to content

Commit c818b15

Browse files
authored
bpo-41520: Fix second codeop regression (GH-21848)
* bpo-41520: Fix second codeop repression Fix the repression introduced by the initial regression fix.
1 parent 46d10b1 commit c818b15

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Lib/codeop.py

+2-2
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

+8-5
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,17 @@ def test_filename(self):
307307

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

314317
# bpo-41520: check SyntaxWarning treated as an SyntaxError
315-
with self.assertRaises(SyntaxError):
318+
with warnings.catch_warnings(), self.assertRaises(SyntaxError):
316319
warnings.simplefilter('error', SyntaxWarning)
317-
compile_command('1 is 1\n', symbol='exec')
320+
compile_command('1 is 1', symbol='exec')
318321

319322

320323
if __name__ == "__main__":
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)