forked from VimPlug/jedi
more complicated logic working with else
This commit is contained in:
@@ -9,6 +9,14 @@ class Status(object):
|
|||||||
self._name = name
|
self._name = name
|
||||||
Status.lookup_table[value] = self
|
Status.lookup_table[value] = self
|
||||||
|
|
||||||
|
def invert(self):
|
||||||
|
if self is REACHABLE:
|
||||||
|
return UNREACHABLE
|
||||||
|
elif self is UNREACHABLE:
|
||||||
|
return REACHABLE
|
||||||
|
else:
|
||||||
|
return UNSURE
|
||||||
|
|
||||||
def __and__(self, other):
|
def __and__(self, other):
|
||||||
if UNSURE in (self, other):
|
if UNSURE in (self, other):
|
||||||
return UNSURE
|
return UNSURE
|
||||||
@@ -27,11 +35,20 @@ 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):
|
||||||
|
invert = False
|
||||||
|
if element_scope.command == 'else':
|
||||||
|
element_scope = element_scope.previous
|
||||||
|
invert = True
|
||||||
|
|
||||||
if element_scope.command == 'if' and element_scope.inputs:
|
if element_scope.command == 'if' and element_scope.inputs:
|
||||||
types = evaluator.eval_statement(element_scope.inputs[0])
|
types = evaluator.eval_statement(element_scope.inputs[0])
|
||||||
values = set(x.py__bool__() for x in types)
|
values = set(x.py__bool__() for x in types)
|
||||||
if len(values) == 1:
|
if len(values) == 1:
|
||||||
reachable = Status.lookup_table[values.pop()]
|
reachable = Status.lookup_table[values.pop()]
|
||||||
|
if invert:
|
||||||
|
reachable = reachable.invert()
|
||||||
|
if reachable is UNREACHABLE:
|
||||||
|
return UNREACHABLE
|
||||||
else:
|
else:
|
||||||
return UNSURE
|
return UNSURE
|
||||||
elif element_scope.command == 'try':
|
elif element_scope.command == 'try':
|
||||||
|
|||||||
@@ -6,3 +6,17 @@ def foo(x):
|
|||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
foo(1)
|
foo(1)
|
||||||
|
|
||||||
|
|
||||||
|
# Exceptions are not analyzed. So check both if branches
|
||||||
|
def try_except(x):
|
||||||
|
try:
|
||||||
|
if 1.0:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
except AttributeError:
|
||||||
|
return 1.0
|
||||||
|
|
||||||
|
#? int() float()
|
||||||
|
try_except(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user