summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compile.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2023-09-13 16:00:39 (GMT)
committerGitHub <noreply@github.com>2023-09-13 16:00:39 (GMT)
commit987b4bc0870e1e29a88275dc3fa39bf2c3dcc763 (patch)
tree92f0ec16bf4377afab41a040266836ed43879c00 /Lib/test/test_compile.py
parent79101edb03b7381b514126c68acabfcbbba2f842 (diff)
downloadcpython-987b4bc0870e1e29a88275dc3fa39bf2c3dcc763.zip
cpython-987b4bc0870e1e29a88275dc3fa39bf2c3dcc763.tar.gz
cpython-987b4bc0870e1e29a88275dc3fa39bf2c3dcc763.tar.bz2
gh-109341: Fix crash on compiling invalid AST including TypeAlias (#109349)
Diffstat (limited to 'Lib/test/test_compile.py')
-rw-r--r--Lib/test/test_compile.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index fa74455..39d972c 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -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