diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 3a5b1747..c771a044 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -151,11 +151,11 @@ class Evaluator(object): for_stmt = stmt.get_parent_until(tree.ForStmt) if isinstance(for_stmt, tree.ForStmt) and types \ - and isinstance(for_stmt.children[1], tree.Name): + and for_stmt.defines_one_name(): # Iterate through result and add the values, that's possible # only in for loops without clutter, because they are # predictable. Also only do it, if the variable is not a tuple. - for_iterable = self.eval_element(for_stmt.children[3]) + for_iterable = self.eval_element(for_stmt.get_input_node()) ordered = iterable.ordered_elements_of_iterable(self, for_iterable, types) for index_types in ordered: diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index 71aa0752..55d995b2 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -988,6 +988,21 @@ class ForStmt(Flow): for node_to_execute in child.nodes_to_execute(): yield node_to_execute + def get_input_node(self): + """ + Returns the input node ``y`` from: ``for x in y:``. + """ + return self.children[3] + + def defines_one_name(self): + """ + Returns True if only one name is returned: ``for x in y``. + Returns False if the for loop is more complicated: ``for x, z in y``. + + :returns: bool + """ + return self.children[1].type == 'name' + class TryStmt(Flow): type = 'try_stmt'