From a4574a50d01e88316ddf554419cae64f547a7d70 Mon Sep 17 00:00:00 2001 From: pyscripter Date: Thu, 25 Apr 2024 12:11:24 +0300 Subject: [PATCH] Fix resolving of names that are not annotations (#1989), fixes #1988 * Fix #1988 * Fix failing code quality test. * Fix flake W504 line break after binary operator. Now as formatted by Black. * Added test to test/completion/pep0484_basic.py Addressed feedback from Dave --- jedi/inference/syntax_tree.py | 7 +++++++ test/completion/pep0484_basic.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 2cd2a140..39503a65 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -695,8 +695,15 @@ 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: found_annotation = True + if ( + (ann_assign.children[1].type == 'name') + and (ann_assign.children[1].value == tree_name.value) + and context.parent_context + ): + context = context.parent_context value_set |= annotation.infer_annotation( context, expr_stmt.children[1].children[1] ).execute_annotation() diff --git a/test/completion/pep0484_basic.py b/test/completion/pep0484_basic.py index e20fe440..7ead7382 100644 --- a/test/completion/pep0484_basic.py +++ b/test/completion/pep0484_basic.py @@ -180,6 +180,11 @@ def argskwargs(*args: int, **kwargs: float): #? float() kwargs[''] +class Test: + str: str = 'abc' + +#? ['upper'] +Test.str.upp class NotCalledClass: def __init__(self, x):