forked from VimPlug/jedi
a first very simple implementation of reachable/unreachable return statements.
This commit is contained in:
@@ -48,6 +48,9 @@ class CompiledObject(Base):
|
|||||||
def py__mro__(self, evaluator):
|
def py__mro__(self, evaluator):
|
||||||
return tuple(create(evaluator, cls) for cls in self.obj.__mro__)
|
return tuple(create(evaluator, cls) for cls in self.obj.__mro__)
|
||||||
|
|
||||||
|
def py__bool__(self):
|
||||||
|
return bool(self.obj)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def doc(self):
|
def doc(self):
|
||||||
return inspect.getdoc(self.obj) or ''
|
return inspect.getdoc(self.obj) or ''
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ from jedi.parser.representation import Flow
|
|||||||
|
|
||||||
|
|
||||||
class Status(object):
|
class Status(object):
|
||||||
def __init__(self, value):
|
lookup_table = {}
|
||||||
|
|
||||||
|
def __init__(self, value, name):
|
||||||
self._value = value
|
self._value = value
|
||||||
|
self._name = name
|
||||||
|
Status.lookup_table[value] = self
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return self._value == other.value
|
return self._value == other.value
|
||||||
@@ -15,20 +19,27 @@ class Status(object):
|
|||||||
if UNSURE in (self, other):
|
if UNSURE in (self, other):
|
||||||
return other
|
return other
|
||||||
else:
|
else:
|
||||||
return REACHABLE if self._value and other._value else NOT_REACHABLE
|
return REACHABLE if self._value and other._value else UNREACHABLE
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<%s: %s>' % (type(self).__name__, self._name)
|
||||||
|
|
||||||
|
|
||||||
NOT_REACHABLE = Status(True)
|
REACHABLE = Status(True, 'reachable')
|
||||||
REACHABLE = Status(False)
|
UNREACHABLE = Status(False, 'unreachable')
|
||||||
UNSURE = Status(None)
|
UNSURE = Status(None, 'unsure')
|
||||||
|
|
||||||
|
|
||||||
def break_check(evaluator, base_scope, element_scope):
|
def break_check(evaluator, base_scope, element_scope):
|
||||||
reachable = REACHABLE
|
reachable = REACHABLE
|
||||||
if isinstance(element_scope, Flow):
|
if isinstance(element_scope, Flow):
|
||||||
if element_scope.command == 'if' and element_scope.inputs:
|
if element_scope.command == 'if' and element_scope.inputs:
|
||||||
result = evaluator.eval_statement(element_scope.inputs[0])
|
types = evaluator.eval_statement(element_scope.inputs[0])
|
||||||
print(result)
|
values = set(x.py__bool__() for x in types)
|
||||||
|
if len(values) == 1:
|
||||||
|
return Status.lookup_table[values.pop()]
|
||||||
|
else:
|
||||||
|
return UNSURE
|
||||||
|
|
||||||
if base_scope != element_scope.parent:
|
if base_scope != element_scope.parent:
|
||||||
return reachable & break_check(base_scope, element_scope.parent)
|
return reachable & break_check(base_scope, element_scope.parent)
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ class FunctionExecution(Executed):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
check = flow_analysis.break_check(self._evaluator, self, r.parent.parent)
|
check = flow_analysis.break_check(self._evaluator, self, r.parent.parent)
|
||||||
if check is not flow_analysis.NOT_REACHABLE:
|
if check is not flow_analysis.UNREACHABLE:
|
||||||
types += self._evaluator.eval_statement(r)
|
types += self._evaluator.eval_statement(r)
|
||||||
if check is flow_analysis.REACHABLE:
|
if check is flow_analysis.REACHABLE:
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user