1
0
forked from VimPlug/jedi

global working.

This commit is contained in:
Dave Halter
2014-11-13 18:13:56 +01:00
parent f3c2b4fc33
commit 13a128b160
4 changed files with 13 additions and 3 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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,

View File

@@ -1152,7 +1152,7 @@ class KeywordStatement(Simple):
class GlobalStmt(Simple):
def names(self):
def get_defined_names(self):
return self.children[1::2]