From 58ef6cd36b2d7214f0dc70d8b8dfda80c241d295 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 5 Aug 2020 23:49:15 +0200 Subject: [PATCH] if_stmt test clauses should be resolved at the start of the if_stmt --- jedi/inference/syntax_tree.py | 5 ++++- test/completion/flow_analysis.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index 0b02d00f..18694d87 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -288,10 +288,13 @@ def infer_atom(context, atom): if atom.type == 'name': # This is the first global lookup. stmt = tree.search_ancestor( - atom, 'expr_stmt', 'lambdef' + atom, 'expr_stmt', 'lambdef', 'if_stmt' ) or atom if stmt.type == 'lambdef': stmt = atom + if stmt.type == 'if_stmt': + if not any(n.start_pos <= atom.start_pos < n.end_pos for n in stmt.get_test_nodes()): + stmt = atom position = stmt.start_pos if _is_annotation_name(atom): # Since Python 3.7 (with from __future__ import annotations), diff --git a/test/completion/flow_analysis.py b/test/completion/flow_analysis.py index 4082fb0e..ed1f0533 100644 --- a/test/completion/flow_analysis.py +++ b/test/completion/flow_analysis.py @@ -5,7 +5,7 @@ x = 3 if NOT_DEFINED: x = '' -#? 6 int() str() +#? 6 int() elif x: pass else: