diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 54e3f587..1f96ff55 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -218,26 +218,20 @@ class Script(object): for s in scopes: if s.isinstance(er.Function): names = s.get_magic_function_names() - else: - if isinstance(s, imports.ImportWrapper): - under = like + self._user_context.get_path_after_cursor() - if under == 'import': - current_line = self._user_context.get_position_line() - if not current_line.endswith('import import'): - continue - a = s.import_stmt.alias - if a and a.start_pos <= self._pos <= a.end_pos: + elif isinstance(s, imports.ImportWrapper): + under = like + self._user_context.get_path_after_cursor() + if under == 'import': + current_line = self._user_context.get_position_line() + if not current_line.endswith('import import'): continue - names = s.get_defined_names(on_import_stmt=True) - else: - try: - sng = s.scope_names_generator - except AttributeError: - names = s.get_defined_names() - else: - names = [] - for _, new_names in sng(): - names += new_names + a = s.import_stmt.alias + if a and a.start_pos <= self._pos <= a.end_pos: + continue + names = s.get_defined_names(on_import_stmt=True) + else: + names = [] + for _, new_names in s.scope_names_generator(): + names += new_names for c in names: completions.append((c, s)) diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 2b52cc13..a01bfdaf 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -11,10 +11,9 @@ would check whether a flow has the form of ``if isinstance(a, type_or_tuple)``. Unfortunately every other thing is being ignored (e.g. a == '' would be easy to check for -> a is a string). There's big potential in these checks. """ -import sys from itertools import chain -from jedi._compatibility import hasattr, unicode, u, reraise +from jedi._compatibility import hasattr, unicode, u from jedi.parser import representation as pr, tokenize from jedi.parser import fast from jedi import debug @@ -513,23 +512,12 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ and non_flow.isinstance(er.Function) or isinstance(scope, compiled.CompiledObject) and scope.type() == 'class' and in_func_scope != scope): - try: - if isinstance(scope, (pr.SubModule, fast.Module)): - scope = er.ModuleWrapper(evaluator, scope) - for g in scope.scope_names_generator(position): - yield g - """ - try: - sng = scope.scope_names_generator - except AttributeError: - yield scope, _get_defined_names_for_position(scope, position, in_func_scope) - else: - for g in sng(position): - yield g - """ - except StopIteration: - reraise(common.MultiLevelStopIteration, sys.exc_info()[2]) + if isinstance(scope, (pr.SubModule, fast.Module)): + scope = er.ModuleWrapper(evaluator, scope) + + for g in scope.scope_names_generator(position): + yield g if scope.isinstance(pr.ListComprehension): # is a list comprehension yield scope, scope.get_defined_names(is_internal_call=True) diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 61704978..802b2e22 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -44,7 +44,7 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)): self.var_args = var_args @underscore_memoization - def get_defined_names(self): + def _get_defined_names(self): """ Returns a list of names that define a generator, which can return the content of a generator. @@ -57,6 +57,9 @@ class Generator(use_metaclass(CachedMetaClass, pr.Base)): else: yield name + def scope_names_generator(self): + yield self, self._get_defined_names() + def iter_content(self): """ returns the content of __iter__ """ return self._evaluator.execute(self.func, self.var_args, True) @@ -172,7 +175,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)): values = [self._array.values[index]] return _follow_values(self._evaluator, values) - def get_defined_names(self): + def scope_names_generator(self): """ This method generates all `ArrayMethod` for one pr.Array. It returns e.g. for a list: append, pop, ... @@ -181,7 +184,7 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)): scope = self._evaluator.find_types(compiled.builtin, self._array.type)[0] scope = self._evaluator.execute(scope)[0] # builtins only have one class names = scope.get_defined_names() - return [ArrayMethod(n) for n in names] + yield self, [ArrayMethod(n) for n in names] @common.safe_property def parent(self):