mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
[3.12] gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352) (#109379)
gh-109351: Fix crash when compiling AST with invalid NamedExpr (GH-109352)
(cherry picked from commit 79101edb03
)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
2fb39f73ed
commit
4b2ba3d0b8
3 changed files with 34 additions and 0 deletions
|
@ -443,6 +443,33 @@ class TestSpecifics(unittest.TestCase):
|
|||
self.assertIn("_A__mangled_mod", A.f.__code__.co_varnames)
|
||||
self.assertIn("__package__", A.f.__code__.co_varnames)
|
||||
|
||||
def test_compile_invalid_namedexpr(self):
|
||||
# gh-109351
|
||||
m = ast.Module(
|
||||
body=[
|
||||
ast.Expr(
|
||||
value=ast.ListComp(
|
||||
elt=ast.NamedExpr(
|
||||
target=ast.Constant(value=1),
|
||||
value=ast.Constant(value=3),
|
||||
),
|
||||
generators=[
|
||||
ast.comprehension(
|
||||
target=ast.Name(id="x", ctx=ast.Store()),
|
||||
iter=ast.Name(id="y", ctx=ast.Load()),
|
||||
ifs=[],
|
||||
is_async=0,
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
],
|
||||
type_ignores=[],
|
||||
)
|
||||
|
||||
with self.assertRaisesRegex(TypeError, "NamedExpr target must be a Name"):
|
||||
compile(ast.fix_missing_locations(m), "<file>", "exec")
|
||||
|
||||
def test_compile_ast(self):
|
||||
fname = __file__
|
||||
if fname.lower().endswith('pyc'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue