if_stmt test clauses should be resolved at the start of the if_stmt

This commit is contained in:
Dave Halter
2020-08-05 23:49:15 +02:00
parent abf63d73d3
commit 58ef6cd36b
2 changed files with 5 additions and 2 deletions

View File

@@ -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),

View File

@@ -5,7 +5,7 @@
x = 3
if NOT_DEFINED:
x = ''
#? 6 int() str()
#? 6 int()
elif x:
pass
else: