diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index ad2ff36c..b4405b08 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -114,8 +114,15 @@ class NameFinder(object): return [n for n in self.scope.get_magic_function_names() if str(n) == str(self.name_str)] + # Need checked for now for the whole names_dict approach. That only + # works on the first name_list_scope, the second one may be the same + # with a different name set (e.g. ModuleWrapper yields the module + # names first and after that it yields the properties that all modules + # have like `__file__`, etc). + checked = set() for name_list_scope, name_list in scope_names_generator: - if hasattr(name_list_scope, 'names_dict'): + if name_list_scope not in checked and hasattr(name_list_scope, 'names_dict'): + checked.add(name_list_scope) names = self.names_dict_lookup(name_list_scope, self.position) if names: break @@ -303,6 +310,8 @@ class NameFinder(object): types += evaluator.eval_element(typ.node_from_name(name)) elif isinstance(typ, pr.Import): types += imports.ImportWrapper(self._evaluator, name).follow() + elif isinstance(typ, pr.GlobalStmt): + types += evaluator.find_types(typ.get_parent_scope(), str(name)) elif isinstance(typ, pr.TryStmt): # TODO an exception can also be a tuple. Check for those. # TODO check for types that are not classes and add it to diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index f25cd95c..7edd880b 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -699,6 +699,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)): def scope_names_generator(self, position=None): yield self, pr.filter_after_position(self._module.get_defined_names(), position) yield self, self._module_attributes() + yield self, self.base.global_names sub_modules = self._sub_modules() if sub_modules: yield self, self._sub_modules() diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 39eddd7c..e99f785a 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -113,7 +113,7 @@ class Parser(object): # We need to check raw_node always, because the same node can be # returned by convert multiple times. if type == pytree.python_symbols.global_stmt: - self.global_names += new_node.names() + self.global_names += new_node.get_defined_names() elif isinstance(new_node, (pr.ClassOrFunc, pr.Module)) \ and type in (pytree.python_symbols.funcdef, pytree.python_symbols.classdef, diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 7470c278..4d9e6ebf 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -1152,7 +1152,7 @@ class KeywordStatement(Simple): class GlobalStmt(Simple): - def names(self): + def get_defined_names(self): return self.children[1::2]