From 0c3cba166effacfdc51c76aff22622368fc51266 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 2 Nov 2014 14:22:00 +0100 Subject: [PATCH] Make names_dict available in modules. --- jedi/evaluate/finder.py | 1 + jedi/evaluate/representation.py | 2 +- jedi/parser/__init__.py | 17 ++++++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index bc1705b8..8b91679b 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -76,6 +76,7 @@ class NameFinder(object): names = [] self.maybe_descriptor = isinstance(self.scope, er.Class) for name_list_scope, name_list in scope_names_generator: + print(name_list_scope, hasattr(name_list_scope, 'names_dict')) break_scopes = [] if not isinstance(name_list_scope, compiled.CompiledObject): # Here is the position stuff happening (sorting of variables). diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 3d1a90dc..f6c2294f 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -436,7 +436,7 @@ class Class(use_metaclass(CachedMetaClass, Wrapper)): def __getattr__(self, name): if name not in ['start_pos', 'end_pos', 'parent', 'asserts', 'raw_doc', 'doc', 'get_imports', 'get_parent_until', 'get_code', - 'subscopes']: + 'subscopes', 'names_dict']: raise AttributeError("Don't touch this: %s of %s !" % (name, self)) return getattr(self.base, name) diff --git a/jedi/parser/__init__.py b/jedi/parser/__init__.py index 073b13e0..6518e851 100644 --- a/jedi/parser/__init__.py +++ b/jedi/parser/__init__.py @@ -81,16 +81,19 @@ class Parser(object): arr.append(new_node) arr = self.scope_names_stack[-1].setdefault(new_node.value, []) arr.append(new_node) - elif isinstance(new_node, pr.ClassOrFunc) \ - and raw_node[0] in (pytree.python_symbols.funcdef, pytree.python_symbols.classdef): + elif isinstance(new_node, (pr.ClassOrFunc, pr.Module)) \ + and raw_node[0] in (pytree.python_symbols.funcdef, + pytree.python_symbols.classdef, + pytree.python_symbols.file_input): # scope_name_stack handling - n = new_node.name scope_names = self.scope_names_stack.pop() - scope_names[n.value].remove(n) + if isinstance(new_node, pr.ClassOrFunc): + n = new_node.name + scope_names[n.value].remove(n) + # Set the func name of the current node + arr = self.scope_names_stack[-1].setdefault(n.value, []) + arr.append(n) new_node.names_dict = scope_names - # Set the func name of the current node - arr = self.scope_names_stack[-1].setdefault(n.value, []) - arr.append(n) return new_node def __init__old__(self, source, module_path=None, no_docstr=False,