From 447ae46b2ff558985657aa22155fe9766a7ee026 Mon Sep 17 00:00:00 2001 From: David Halter Date: Fri, 30 Nov 2012 16:52:22 +0100 Subject: [PATCH] fixes a bug with magic functions of functions --- jedi/builtin.py | 10 +++++----- jedi/evaluate.py | 11 +++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/jedi/builtin.py b/jedi/builtin.py index 6d05984d..dabfc52b 100644 --- a/jedi/builtin.py +++ b/jedi/builtin.py @@ -452,9 +452,9 @@ class Builtin(object): return self.builtin.parser.module @property - def magic_function_names(self): + def magic_function_scope(self): try: - return self._magic_function_names + return self._magic_function_scope except AttributeError: # depth = 1 because this is not a module class Container(object): @@ -463,11 +463,11 @@ class Builtin(object): parser = parsing.PyFuzzyParser(source, None) # needed for caching (because of weakref) module = self.magic_func_module = parser.module + module.parent = lambda: self.scope typ = evaluate.follow_path(iter(['FunctionType']), module, module) - names = typ.pop().get_defined_names() - self._magic_function_names = names - return names + self._magic_function_scope = s = typ.pop() + return s Builtin = Builtin() diff --git a/jedi/evaluate.py b/jedi/evaluate.py index 500ca44f..3028724a 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -456,7 +456,10 @@ class Function(use_metaclass(CachedMetaClass, parsing.Base)): return self._decorated_func def get_magic_method_names(self): - return builtin.Builtin.magic_function_names + return builtin.Builtin.magic_function_scope.get_defined_names() + + def get_magic_method_scope(self): + return builtin.Builtin.magic_function_scope def __getattr__(self, name): return getattr(self.base_func, name) @@ -1552,13 +1555,13 @@ def follow_path(path, scope, call_scope, position=None): else: # The function must not be decorated with something else. if scope.isinstance(Function): - result = scope.get_magic_method_names() + scope = scope.get_magic_method_scope() else: # 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, - position=position)) + result = imports.strip_imports(get_scopes_for_name(scope, current, + position=position)) return follow_paths(path, set(result), call_scope, position=position)