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:
Serhiy Storchaka 2025-10-30 13:00:42 +02:00 committed by GitHub
parent 2a904263aa
commit ad0a3f733b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 98 additions and 61 deletions

View file

@ -1057,61 +1057,6 @@ def test_repr_large_input_crash(self):
r"Exceeds the limit \(\d+ digits\)"):
repr(ast.Constant(value=eval(source)))
def test_pep_765_warnings(self):
srcs = [
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
"""),
]
for src in srcs:
with self.assertWarnsRegex(SyntaxWarning, 'finally'):
ast.parse(src)
def test_pep_765_no_warnings(self):
srcs = [
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
"""),
]
for src in srcs:
ast.parse(src)
def test_tstring(self):
# Test AST structure for simple t-string
tree = ast.parse('t"Hello"')