From f8fb2d1230993ee419ddf6efcd601a4d75108f46 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 1 May 2026 13:05:22 +0200 Subject: [PATCH] Basic support for TypeAlias, fixes #1969 --- jedi/inference/syntax_tree.py | 7 +++++-- test/completion/pep0484_typing.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index c5d9400b..071fb8d4 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -703,9 +703,12 @@ def tree_name_to_values(inference_state, context, tree_name): if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign": correct_scope = parser_utils.get_parent_scope(name) == context.tree_node ann_assign = expr_stmt.children[1] - if correct_scope: + first = ann_assign.children[1] + code = first.get_code() + if correct_scope and not (code.endswith(".TypeAlias") + or code.strip() == "TypeAlias"): if ( - (ann_assign.children[1].type == 'name') + (first.type == 'name') and (ann_assign.children[1].value == tree_name.value) and context.parent_context ): diff --git a/test/completion/pep0484_typing.py b/test/completion/pep0484_typing.py index d986d4d5..d0deba0f 100644 --- a/test/completion/pep0484_typing.py +++ b/test/completion/pep0484_typing.py @@ -587,3 +587,20 @@ b.add_x(2).add_y(5) b.add_x(2).add_not_implemented(5) #? Builder() b.add_x(2).add_not_implemented_typing_extensions(5) + +# ----------------- +# TypeAlias (see also #1969) +# ----------------- + +from typing import TypeAlias + +IntX: typing.TypeAlias = int +IntY: TypeAlias = int + +#? int +IntX +def f(x: IntX, y: IntY): + #? int() + x + #? int() + y