Skip to content

Commit a3416c1

Browse files
[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]> (cherry picked from commit f24430f) Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent afff51f commit a3416c1

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
@@ -297,14 +297,17 @@ def test_filename(self):
297297

298298
def test_warning(self):
299299
# Test that the warning is only returned once.
300-
with support.check_warnings((".*literal", SyntaxWarning)) as w:
301-
compile_command("0 is 0")
302-
self.assertEqual(len(w.warnings), 1)
300+
with support.check_warnings(
301+
(".*literal", SyntaxWarning),
302+
(".*invalid", DeprecationWarning),
303+
) as w:
304+
compile_command(r"'\e' is 0")
305+
self.assertEqual(len(w.warnings), 2)
303306

304307
# bpo-41520: check SyntaxWarning treated as an SyntaxError
305-
with self.assertRaises(SyntaxError):
308+
with warnings.catch_warnings(), self.assertRaises(SyntaxError):
306309
warnings.simplefilter('error', SyntaxWarning)
307-
compile_command('1 is 1\n', symbol='exec')
310+
compile_command('1 is 1', symbol='exec')
308311

309312

310313
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)