From 68bd9160e2a989643c30e7ea80de73ba6d194ffd Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 1 Dec 2014 00:08:27 +0100 Subject: [PATCH] Fixed list comprehension name lookups. --- jedi/evaluate/__init__.py | 2 ++ jedi/evaluate/iterable.py | 3 +++ jedi/evaluate/recursion.py | 6 ------ jedi/parser/user_context.py | 10 +++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 91d0e5ba..bfdfc055 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -215,6 +215,8 @@ class Evaluator(object): # This is the first global lookup. stmt = atom.get_definition() scope = stmt.get_parent_until(pr.IsScope, include_current=True) + if isinstance(stmt, pr.CompFor): + stmt = stmt.get_parent_until((pr.ClassOrFunc, pr.ExprStmt)) return self.find_types(scope, atom, stmt.start_pos, search_global=True) elif isinstance(atom, pr.Literal): return [compiled.create(self, atom.eval())] diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index a6cb4119..89886549 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -151,6 +151,9 @@ class Comprehension(IterableWrapper): return helpers.deep_ast_copy(comprehension.children[0], {comprehension: last_comp}) + def get_exact_index_types(self, index): + return [self._evaluator.eval_element(self.eval_node())[index]] + def __repr__(self): return "" % (type(self).__name__, self._atom) diff --git a/jedi/evaluate/recursion.py b/jedi/evaluate/recursion.py index 7d7a1b38..6ea2e961 100644 --- a/jedi/evaluate/recursion.py +++ b/jedi/evaluate/recursion.py @@ -88,14 +88,8 @@ class _RecursionNode(object): if not other: return None - # List Comprehensions start on the same line as its statement. - # Therefore we have the unfortunate situation of the same start_pos for - # two statements. - is_list_comp = lambda x: isinstance(x, pr.ListComprehension) return self.script == other.script \ and self.position == other.position \ - and not is_list_comp(self.stmt.parent) \ - and not is_list_comp(other.parent) \ and not self.is_ignored and not other.is_ignored diff --git a/jedi/parser/user_context.py b/jedi/parser/user_context.py index 437a6e78..f30058ca 100644 --- a/jedi/parser/user_context.py +++ b/jedi/parser/user_context.py @@ -81,14 +81,14 @@ class UserContext(object): return u(''), start_cursor is_first = False - # print 'tok', token_type, tok_str, force_point + #print('tok', tok_type, tok_str, force_point) if last_type == tok_type == tokenize.NAME: string += ' ' - if level > 0: + if level: if tok_str in close_brackets: level += 1 - if tok_str in open_brackets: + elif tok_str in open_brackets: level -= 1 elif tok_str == '.': force_point = False @@ -127,10 +127,10 @@ class UserContext(object): l = first_line if x == start_pos[0] else l start_cursor = x, len(l) - end[1] string += tok_str - if keyword.iskeyword(tok_str[::-1]): + #if keyword.iskeyword(tok_str[::-1]): # Keywords should always stop. The path will always end with # them. - break + # break last_type = tok_type # string can still contain spaces at the end