Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[3.9] bpo-41520: Fix second codeop regression (GH-21848)
Fix the repression introduced by the initial regression fix.

(cherry picked from commit c818b15)
  • Loading branch information
terryjreedy committed Aug 13, 2020
commit 64ee42c073e10a78ba9cd57095f4ab418bf745a8
4 changes: 2 additions & 2 deletions Lib/codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions Lib/test/test_codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,17 @@ def test_filename(self):

def test_warning(self):
# Test that the warning is only returned once.
with support.check_warnings((".*literal", SyntaxWarning)) as w:
compile_command("0 is 0")
self.assertEqual(len(w.warnings), 1)
with support.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__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fix :mod:`codeop` regression: it no longer ignores :exc:`SyntaxWarning`.
Fix :mod:`codeop` regression that prevented turning compile warnings into errors.