diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2023-09-13 16:00:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-13 16:00:15 (GMT) |
commit | 79101edb03b7381b514126c68acabfcbbba2f842 (patch) | |
tree | d32d6fa1b4d763accf7a033ecb065a0f8cc05d04 /Lib | |
parent | d69805b38a1815e7aaadf49bdd019c7cca105ac6 (diff) | |
download | cpython-79101edb03b7381b514126c68acabfcbbba2f842.zip cpython-79101edb03b7381b514126c68acabfcbbba2f842.tar.gz cpython-79101edb03b7381b514126c68acabfcbbba2f842.tar.bz2 |
gh-109351: Fix crash when compiling AST with invalid NamedExpr (#109352)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_compile.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index a8a519f..fa74455 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -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'): |