mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-131927: Do not emit PEP 765 warnings in ast.parse() (GH-139642)
ast.parse() no longer emits syntax warnings for return/break/continue in finally (see PEP-765) -- they are only emitted during compilation.
This commit is contained in:
parent
2a904263aa
commit
ad0a3f733b
7 changed files with 98 additions and 61 deletions
|
|
@ -1745,6 +1745,66 @@ def test_compile_warning_in_finally(self):
|
|||
self.assertEqual(wm.category, SyntaxWarning)
|
||||
self.assertIn("\"is\" with 'int' literal", str(wm.message))
|
||||
|
||||
@support.subTests('src', [
|
||||
textwrap.dedent("""
|
||||
def f():
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
return 42
|
||||
"""),
|
||||
textwrap.dedent("""
|
||||
for x in y:
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
break
|
||||
"""),
|
||||
textwrap.dedent("""
|
||||
for x in y:
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
continue
|
||||
"""),
|
||||
])
|
||||
def test_pep_765_warnings(self, src):
|
||||
with self.assertWarnsRegex(SyntaxWarning, 'finally'):
|
||||
compile(src, '<string>', 'exec')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
tree = ast.parse(src)
|
||||
with self.assertWarnsRegex(SyntaxWarning, 'finally'):
|
||||
compile(tree, '<string>', 'exec')
|
||||
|
||||
@support.subTests('src', [
|
||||
textwrap.dedent("""
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
def f():
|
||||
return 42
|
||||
"""),
|
||||
textwrap.dedent("""
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
for x in y:
|
||||
break
|
||||
"""),
|
||||
textwrap.dedent("""
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
for x in y:
|
||||
continue
|
||||
"""),
|
||||
])
|
||||
def test_pep_765_no_warnings(self, src):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
compile(src, '<string>', 'exec')
|
||||
|
||||
|
||||
class TestBooleanExpression(unittest.TestCase):
|
||||
class Value:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue