diff --git a/jedi/evaluate.py b/jedi/evaluate.py index 70e74b00..a453a069 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -162,7 +162,7 @@ def get_names_of_scope(scope, position=None, star_search=True, yield builtin_scope, builtin_scope.get_defined_names() -def get_scopes_for_name(scope, name_str, position=None, search_global=False, +def find_name(scope, name_str, position=None, search_global=False, is_goto=False): """ This is the search function. The most important part to debug. @@ -193,8 +193,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False, if r.is_global(): for token_name in r.token_list[1:]: if isinstance(token_name, pr.Name): - add = get_scopes_for_name(r.parent, - str(token_name)) + add = find_name(r.parent, str(token_name)) else: # generated objects are used within executions, but these # objects are in functions, and we have to dynamically @@ -660,12 +659,12 @@ def follow_call_path(path, scope, position): else: if isinstance(current, pr.NamePart): # This is the first global lookup. - scopes = get_scopes_for_name(scope, current, position=position, + scopes = find_name(scope, current, position=position, search_global=True) else: if current.type in (pr.Call.STRING, pr.Call.NUMBER): t = type(current.name).__name__ - scopes = get_scopes_for_name(builtin.Builtin.scope, t) + scopes = find_name(builtin.Builtin.scope, t) else: debug.warning('unknown type:', current.type, current) scopes = [] @@ -734,7 +733,7 @@ def follow_path(path, scope, call_scope, position=None): # This is the typical lookup while chaining things. if filter_private_variable(scope, call_scope, current): return [] - result = imports.strip_imports(get_scopes_for_name(scope, current, + result = imports.strip_imports(find_name(scope, current, position=position)) return follow_paths(path, set(result), call_scope, position=position) @@ -769,6 +768,6 @@ def goto(stmt, call_path=None): search_global = True follow_res = [] for s in scopes: - follow_res += get_scopes_for_name(s, search, pos, + follow_res += find_name(s, search, pos, search_global=search_global, is_goto=True) return follow_res, search diff --git a/jedi/evaluate_representation.py b/jedi/evaluate_representation.py index ebb29242..285ff1f8 100644 --- a/jedi/evaluate_representation.py +++ b/jedi/evaluate_representation.py @@ -248,8 +248,7 @@ class Class(use_metaclass(cache.CachedMetaClass, pr.Base)): supers.append(cls) if not supers and self.base.parent != builtin.Builtin.scope: # add `object` to classes - supers += evaluate.get_scopes_for_name(builtin.Builtin.scope, - 'object') + supers += evaluate.find_name(builtin.Builtin.scope, 'object') return supers @cache.memoize_default(default=[]) @@ -813,8 +812,7 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)): It returns e.g. for a list: append, pop, ... """ # `array.type` is a string with the type, e.g. 'list'. - scope = evaluate.get_scopes_for_name(builtin.Builtin.scope, - self._array.type)[0] + scope = evaluate.find_name(builtin.Builtin.scope, self._array.type)[0] scope = Instance(scope) names = scope.get_defined_names() return [ArrayElement(n) for n in names] diff --git a/jedi/imports.py b/jedi/imports.py index f622f622..cc79106c 100644 --- a/jedi/imports.py +++ b/jedi/imports.py @@ -185,8 +185,8 @@ class ImportPath(pr.Base): elif rest: if is_goto: scopes = itertools.chain.from_iterable( - evaluate.get_scopes_for_name(s, rest[0], is_goto=True) - for s in scopes) + evaluate.find_name(s, rest[0], is_goto=True) + for s in scopes) else: scopes = itertools.chain.from_iterable( evaluate.follow_path(iter(rest), s, s)