context -> value

This commit is contained in:
Dave Halter
2019-08-15 01:23:06 +02:00
parent 9e23f4d67b
commit ad4f546aca
68 changed files with 1931 additions and 1931 deletions

View File

@@ -41,7 +41,7 @@ def _get_flow_scopes(node):
yield node
def reachability_check(context, context_scope, node, origin_scope=None):
def reachability_check(value, 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(context, context_scope, node, origin_scope=None):
return REACHABLE
origin_scope = origin_scope.parent
return _break_check(context, context_scope, first_flow_scope, node)
return _break_check(value, value_scope, first_flow_scope, node)
def _break_check(context, context_scope, flow_scope, node):
def _break_check(value, 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(context, check_node)
reachable = _check_if(value, 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(context, flow_node)
reachable = _check_if(value, flow_node)
elif flow_scope.type in ('try_stmt', 'while_stmt'):
return UNSURE
@@ -98,19 +98,19 @@ def _break_check(context, context_scope, flow_scope, node):
if reachable in (UNREACHABLE, UNSURE):
return reachable
if context_scope != flow_scope and context_scope != flow_scope.parent:
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(context, context_scope, flow_scope, node)
return reachable & _break_check(value, value_scope, flow_scope, node)
else:
return reachable
def _check_if(context, node):
with execution_allowed(context.infer_state, node) as allowed:
def _check_if(value, node):
with execution_allowed(value.infer_state, node) as allowed:
if not allowed:
return UNSURE
types = context.infer_node(node)
types = value.infer_node(node)
values = set(x.py__bool__() for x in types)
if len(values) == 1:
return Status.lookup_table[values.pop()]