diff --git a/jedi/evaluate.py b/jedi/evaluate.py index db375f1a..ff3a155d 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -568,7 +568,7 @@ def follow_call_list(call_list, follow_array=False): # create a for loop, which does the same as list comprehensions loop = pr.ForFlow(module, [input], lc.stmt.start_pos, lc.middle, True) - loop.parent = lc.parent if parent is None else parent + loop.parent = parent or lc.get_parent_until(pr.IsScope) if isinstance(nested_lc, pr.ListComprehension): loop = evaluate_list_comprehension(nested_lc, loop) diff --git a/jedi/parsing.py b/jedi/parsing.py index a38aa82a..b25cdfd5 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -435,7 +435,8 @@ class Parser(object): st = pr.Statement(self.module, src, [], [], [], toks, first_pos, self.end_pos) - tok = pr.ListComprehension(st, middle, in_clause) + tok = pr.ListComprehension(st, middle, in_clause, + self.scope) tok_list.append(tok) if list_comp: string = '' diff --git a/jedi/parsing_representation.py b/jedi/parsing_representation.py index ac50c3d9..2c727bca 100644 --- a/jedi/parsing_representation.py +++ b/jedi/parsing_representation.py @@ -93,8 +93,9 @@ class Simple(Base): def __repr__(self): code = self.get_code().replace('\n', ' ') + # TODO (this todo doesn't belong here) positions are not added right. return "<%s: %s@%s,%s>" % \ - (type(self).__name__, code, self.start_pos[0], self.start_pos[0]) + (type(self).__name__, code, self.start_pos[0], self.start_pos[1]) class IsScope(Base): @@ -1174,13 +1175,13 @@ class Name(Simple): class ListComprehension(Base): """ Helper class for list comprehensions """ - def __init__(self, stmt, middle, input): + def __init__(self, stmt, middle, input, parent): self.stmt = stmt self.middle = middle self.input = input for s in [stmt, middle, input]: s.parent = self - self.parent = None + self.parent = parent def get_parent_until(self, *args, **kwargs): return Simple.get_parent_until(self, *args, **kwargs)