1
0
forked from VimPlug/jedi

Improve flow analysis a bit.

This commit is contained in:
Dave Halter
2014-11-05 19:18:45 +01:00
parent 9549c2b389
commit 186ce2b70a
6 changed files with 52 additions and 26 deletions

View File

@@ -845,7 +845,34 @@ class Flow(Simple):
class IfStmt(Flow):
pass
def check_nodes(self):
"""
Returns all the `test` nodes that are defined as x, here:
if x:
pass
elif x:
pass
"""
for i, c in enumerate(self.children):
if c in ('elif', 'if'):
yield self.children[i + 1]
def node_in_which_check_node(self, node):
for check_node in reversed(list(self.check_nodes())):
if check_node.start_pos < node.start_pos:
return check_node
def node_after_else(self, node):
"""
Checks if a node is defined after `else`.
"""
for c in self.children:
if c == 'else':
if node.start_pos > c.start_pos:
return True
else:
return False
class WhileStmt(Flow):