diff --git a/jedi/evaluate/flow_analysis.py b/jedi/evaluate/flow_analysis.py index a118adc5..403837cb 100644 --- a/jedi/evaluate/flow_analysis.py +++ b/jedi/evaluate/flow_analysis.py @@ -1,7 +1,35 @@ +from jedi.parser.representation import Flow -NOT_REACHABLE = object() -REACHABLE = object() -UNSURE = object() -def break_check(scope): +class Status(object): + def __init__(self, value): + self._value = value + + def __eq__(self, other): + return self._value == other.value + + def __ne__(self, other): + return not self.__eq__(other) + + def __and__(self, other): + if UNSURE in (self, other): + return other + else: + return REACHABLE if self._value and other._value else NOT_REACHABLE + + +NOT_REACHABLE = Status(True) +REACHABLE = Status(False) +UNSURE = Status(None) + + +def break_check(evaluator, base_scope, element_scope): + reachable = REACHABLE + if isinstance(element_scope, Flow): + if element_scope.command == 'if' and element_scope.inputs: + result = evaluator.eval_statement(element_scope.inputs[0]) + print(result) + + if base_scope != element_scope.parent: + return reachable & break_check(base_scope, element_scope.parent) return UNSURE diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index c7ce18fe..ef285ae7 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -475,7 +475,7 @@ class FunctionExecution(Executed): if r is None: continue - check = flow_analysis.break_check(r.parent.parent) + check = flow_analysis.break_check(self._evaluator, self, r.parent.parent) if check is not flow_analysis.NOT_REACHABLE: types += self._evaluator.eval_statement(r) if check is flow_analysis.REACHABLE: