gh-109341: Fix crash on compiling invalid AST including TypeAlias (#109349)

This commit is contained in:
Jelle Zijlstra 2023-09-13 09:00:39 -07:00 committed by GitHub
parent 79101edb03
commit 987b4bc087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View file

@ -505,6 +505,26 @@ class TestSpecifics(unittest.TestCase):
ast.body = [_ast.BoolOp()]
self.assertRaises(TypeError, compile, ast, '<ast>', 'exec')
def test_compile_invalid_typealias(self):
# gh-109341
m = ast.Module(
body=[
ast.TypeAlias(
name=ast.Subscript(
value=ast.Name(id="foo", ctx=ast.Load()),
slice=ast.Constant(value="x"),
ctx=ast.Store(),
),
type_params=[],
value=ast.Name(id="Callable", ctx=ast.Load()),
)
],
type_ignores=[],
)
with self.assertRaisesRegex(TypeError, "TypeAlias with non-Name name"):
compile(ast.fix_missing_locations(m), "<file>", "exec")
def test_dict_evaluation_order(self):
i = 0