mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.9] bpo-41520: Fix second codeop regression (GH-21848)
Fix the repression introduced by the initial regression fix.
(cherry picked from commit c818b15fa5
)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
b3ad2ca56a
commit
f24430f154
3 changed files with 11 additions and 8 deletions
|
@ -85,9 +85,9 @@ def _maybe_compile(compiler, source, filename, symbol):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Catch syntax warnings after the first compile
|
# 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():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("error", SyntaxWarning)
|
warnings.simplefilter("error")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
code1 = compiler(source + "\n", filename, symbol)
|
code1 = compiler(source + "\n", filename, symbol)
|
||||||
|
|
|
@ -306,14 +306,17 @@ class CodeopTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_warning(self):
|
def test_warning(self):
|
||||||
# Test that the warning is only returned once.
|
# Test that the warning is only returned once.
|
||||||
with support.check_warnings((".*literal", SyntaxWarning)) as w:
|
with support.check_warnings(
|
||||||
compile_command("0 is 0")
|
(".*literal", SyntaxWarning),
|
||||||
self.assertEqual(len(w.warnings), 1)
|
(".*invalid", DeprecationWarning),
|
||||||
|
) as w:
|
||||||
|
compile_command(r"'\e' is 0")
|
||||||
|
self.assertEqual(len(w.warnings), 2)
|
||||||
|
|
||||||
# bpo-41520: check SyntaxWarning treated as an SyntaxError
|
# bpo-41520: check SyntaxWarning treated as an SyntaxError
|
||||||
with self.assertRaises(SyntaxError):
|
with warnings.catch_warnings(), self.assertRaises(SyntaxError):
|
||||||
warnings.simplefilter('error', SyntaxWarning)
|
warnings.simplefilter('error', SyntaxWarning)
|
||||||
compile_command('1 is 1\n', symbol='exec')
|
compile_command('1 is 1', symbol='exec')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Fix :mod:`codeop` regression: it no longer ignores :exc:`SyntaxWarning`.
|
Fix :mod:`codeop` regression that prevented turning compile warnings into errors.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue