From a62b282eeb95b52b94204c8822eb27ace3ee964a Mon Sep 17 00:00:00 2001 From: pyscripter Date: Wed, 17 Apr 2024 17:11:23 +0300 Subject: [PATCH 1/4] Fix #1988 --- jedi/inference/syntax_tree.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 2cd2a1400..11e2c2834 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -695,8 +695,13 @@ 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 - if correct_scope: + ann_assign = expr_stmt.children[1] + if correct_scope and name.start_pos < ann_assign.start_pos: found_annotation = True + if (expr_stmt.children[1].children[1].type == 'name') and \ + (expr_stmt.children[1].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() From f8a68ecb9db31ed039a3abe78ddac37bc38cd05c Mon Sep 17 00:00:00 2001 From: pyscripter Date: Wed, 17 Apr 2024 17:35:37 +0300 Subject: [PATCH 2/4] Fix failing code quality test. --- jedi/inference/syntax_tree.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 11e2c2834..45a3b637e 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -698,9 +698,9 @@ def tree_name_to_values(inference_state, context, tree_name): ann_assign = expr_stmt.children[1] if correct_scope and name.start_pos < ann_assign.start_pos: found_annotation = True - if (expr_stmt.children[1].children[1].type == 'name') and \ - (expr_stmt.children[1].children[1].value == tree_name.value) and \ - context.parent_context: + if ((expr_stmt.children[1].children[1].type == 'name') and + (expr_stmt.children[1].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] From d3284864742a9e60672270b5fc107eaf9c11bdfb Mon Sep 17 00:00:00 2001 From: pyscripter Date: Wed, 17 Apr 2024 17:53:10 +0300 Subject: [PATCH 3/4] Fix flake W504 line break after binary operator. Now as formatted by Black. --- jedi/inference/syntax_tree.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 45a3b637e..8311edc77 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -698,9 +698,11 @@ def tree_name_to_values(inference_state, context, tree_name): ann_assign = expr_stmt.children[1] if correct_scope and name.start_pos < ann_assign.start_pos: found_annotation = True - if ((expr_stmt.children[1].children[1].type == 'name') and - (expr_stmt.children[1].children[1].value == tree_name.value) and - context.parent_context): + if ( + (expr_stmt.children[1].children[1].type == 'name') + and (expr_stmt.children[1].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] From f46a4d8963e1efb77973997b9d3d1f405e5c529e Mon Sep 17 00:00:00 2001 From: pyscripter Date: Mon, 22 Apr 2024 16:47:17 +0300 Subject: [PATCH 4/4] Added test to test/completion/pep0484_basic.py Addressed feedback from Dave --- jedi/inference/syntax_tree.py | 6 +++--- test/completion/pep0484_basic.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 8311edc77..39503a658 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -696,11 +696,11 @@ 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 and name.start_pos < ann_assign.start_pos: + if correct_scope: found_annotation = True if ( - (expr_stmt.children[1].children[1].type == 'name') - and (expr_stmt.children[1].children[1].value == tree_name.value) + (ann_assign.children[1].type == 'name') + and (ann_assign.children[1].value == tree_name.value) and context.parent_context ): context = context.parent_context diff --git a/test/completion/pep0484_basic.py b/test/completion/pep0484_basic.py index e20fe4408..7ead7382d 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):