1
0
forked from VimPlug/jedi

Add a method 'Name.assignment_indexes', to process tuple assignments.

This commit is contained in:
Dave Halter
2014-10-21 15:45:29 +02:00
parent c1807e5f33
commit 5b29e2c54d
3 changed files with 42 additions and 4 deletions

View File

@@ -225,6 +225,28 @@ class Name(_Leaf):
def get_definition(self):
return self.parent.get_parent_until((ArrayStmt, StatementElement, Node), reverse=True)
def assignment_indexes(self):
"""
Returns an array of ints of the indexes that are used in tuple
assignments.
For example if the name is ``y`` in the following code::
x, (y, z) = 2, ''
would result in ``[1, 0]``.
"""
indexes = []
node = self.parent
while node is not None:
if is_node(node, 'testlist_comp') or is_node(node, 'testlist_star_expr'):
for i, child in enumerate(node.children):
if child == self:
indexes.insert(0, i)
node = node.parent
return indexes
class Literal(_Leaf):
def eval(self):