From e647e09f0cedb7715e2121f10d5080b9ff9cc584 Mon Sep 17 00:00:00 2001 From: David Halter Date: Mon, 24 Dec 2012 10:47:11 +0100 Subject: [PATCH] fix problems with unnecessary brackets and following executions, which fixes also the last remaining lambda problem --- jedi/evaluate.py | 24 ++++++++++++++++-------- jedi/parsing.py | 2 -- test/completion/arrays.py | 2 ++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/jedi/evaluate.py b/jedi/evaluate.py index 73d88562..7bd19740 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -1328,7 +1328,7 @@ def follow_statement(stmt, seek_name=None): return set(result) -def follow_call_list(call_list): +def follow_call_list(call_list, follow_array=False): """ The call_list has a special structure. This can be either `parsing.Array` or `list of list`. @@ -1364,7 +1364,7 @@ def follow_call_list(call_list): calls_iterator = iter(calls) for call in calls_iterator: if parsing.Array.is_type(call, parsing.Array.NOARRAY): - result += follow_call_list(call) + result += follow_call_list(call, follow_array=True) elif isinstance(call, parsing.ListComprehension): loop = evaluate_list_comprehension(call) stmt = copy.copy(call.stmt) @@ -1401,6 +1401,14 @@ def follow_call_list(call_list): and str(r.name) == 'str']: # if it is an iterable, ignore * operations next(calls_iterator) + + if follow_array and isinstance(call_list, parsing.Array): + # call_list can also be a two dimensional array + call_path = call_list.generate_call_path() + next(call_path, None) # the first one has been used already + call_scope = call_list.parent_stmt + position = call_list.start_pos + result = follow_paths(call_path, result, call_scope, position=position) return set(result) @@ -1419,7 +1427,11 @@ def follow_call_path(path, scope, position): if isinstance(current, parsing.Array): result = [Array(current)] else: - if not isinstance(current, parsing.NamePart): + if isinstance(current, parsing.NamePart): + # This is the first global lookup. + scopes = get_scopes_for_name(scope, current, position=position, + search_global=True) + else: if current.type in (parsing.Call.STRING, parsing.Call.NUMBER): t = type(current.name).__name__ scopes = get_scopes_for_name(builtin.Builtin.scope, t) @@ -1429,10 +1441,6 @@ def follow_call_path(path, scope, position): # Make instances of those number/string objects. arr = helpers.generate_param_array([current.name]) scopes = [Instance(s, arr) for s in scopes] - else: - # This is the first global lookup. - scopes = get_scopes_for_name(scope, current, position=position, - search_global=True) result = imports.strip_imports(scopes) return follow_paths(path, result, scope, position=position) @@ -1467,7 +1475,7 @@ def follow_path(path, scope, call_scope, position=None): `follow_path` is only responsible for completing `.bar.baz`, the rest is done in the `follow_call` function. """ - # Current is either an Array or a Scope. + # current is either an Array or a Scope. try: current = next(path) except StopIteration: diff --git a/jedi/parsing.py b/jedi/parsing.py index f4e8e24a..a9bf3d26 100644 --- a/jedi/parsing.py +++ b/jedi/parsing.py @@ -1322,7 +1322,6 @@ class PyFuzzyParser(object): n = Name(self.module, names, first_pos, self.end_pos) if names \ else None - #if self.module.path != '__builtin__': print n return n, token_type, tok def _parseimportlist(self): @@ -1558,7 +1557,6 @@ class PyFuzzyParser(object): lambd.returns.append(ret) lambd.parent = self.scope lambd.end_pos = self.end_pos - #print lambd, added_breaks, ret, param tok_list[-1] = lambd continue elif token_type == tokenize.NAME: diff --git a/test/completion/arrays.py b/test/completion/arrays.py index f095ad9a..97d00ba4 100644 --- a/test/completion/arrays.py +++ b/test/completion/arrays.py @@ -125,6 +125,8 @@ def a(): return '' (a)().replace() #? int() (tuple).index() +#? int() +(tuple)().index() # -----------------