1
0
forked from VimPlug/jedi

more complicated logic working with else

This commit is contained in:
Dave Halter
2014-08-07 12:02:08 +02:00
parent d94a70b524
commit ee65764c3a
2 changed files with 31 additions and 0 deletions

View File

@@ -9,6 +9,14 @@ class Status(object):
self._name = name
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):
if UNSURE in (self, other):
return UNSURE
@@ -27,11 +35,20 @@ UNSURE = Status(None, 'unsure')
def break_check(evaluator, base_scope, element_scope):
reachable = REACHABLE
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:
types = evaluator.eval_statement(element_scope.inputs[0])
values = set(x.py__bool__() for x in types)
if len(values) == 1:
reachable = Status.lookup_table[values.pop()]
if invert:
reachable = reachable.invert()
if reachable is UNREACHABLE:
return UNREACHABLE
else:
return UNSURE
elif element_scope.command == 'try':

View File

@@ -6,3 +6,17 @@ def foo(x):
#? int()
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)