1
0
forked from VimPlug/jedi

Start working on replacing value partially with context

This commit is contained in:
Dave Halter
2019-08-16 13:00:05 +02:00
parent 03920502c4
commit d19233a338
6 changed files with 124 additions and 118 deletions

View File

@@ -41,7 +41,7 @@ def _get_flow_scopes(node):
yield node
def reachability_check(value, value_scope, node, origin_scope=None):
def reachability_check(context, value_scope, node, origin_scope=None):
first_flow_scope = get_parent_scope(node, include_flows=True)
if origin_scope is not None:
origin_flow_scopes = list(_get_flow_scopes(origin_scope))
@@ -75,22 +75,22 @@ def reachability_check(value, value_scope, node, origin_scope=None):
return REACHABLE
origin_scope = origin_scope.parent
return _break_check(value, value_scope, first_flow_scope, node)
return _break_check(context, value_scope, first_flow_scope, node)
def _break_check(value, value_scope, flow_scope, node):
def _break_check(context, value_scope, flow_scope, node):
reachable = REACHABLE
if flow_scope.type == 'if_stmt':
if flow_scope.is_node_after_else(node):
for check_node in flow_scope.get_test_nodes():
reachable = _check_if(value, check_node)
reachable = _check_if(context, check_node)
if reachable in (REACHABLE, UNSURE):
break
reachable = reachable.invert()
else:
flow_node = flow_scope.get_corresponding_test_node(node)
if flow_node is not None:
reachable = _check_if(value, flow_node)
reachable = _check_if(context, flow_node)
elif flow_scope.type in ('try_stmt', 'while_stmt'):
return UNSURE
@@ -100,17 +100,17 @@ def _break_check(value, value_scope, flow_scope, node):
if value_scope != flow_scope and value_scope != flow_scope.parent:
flow_scope = get_parent_scope(flow_scope, include_flows=True)
return reachable & _break_check(value, value_scope, flow_scope, node)
return reachable & _break_check(context, value_scope, flow_scope, node)
else:
return reachable
def _check_if(value, node):
with execution_allowed(value.inference_state, node) as allowed:
def _check_if(context, node):
with execution_allowed(context.inference_state, node) as allowed:
if not allowed:
return UNSURE
types = value.infer_node(node)
types = context.infer_node(node)
values = set(x.py__bool__() for x in types)
if len(values) == 1:
return Status.lookup_table[values.pop()]