diff --git a/jedi/evaluate/context/klass.py b/jedi/evaluate/context/klass.py index 224957b1..31572501 100644 --- a/jedi/evaluate/context/klass.py +++ b/jedi/evaluate/context/klass.py @@ -136,7 +136,7 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)): arglist = self.tree_node.get_super_arglist() if arglist: from jedi.evaluate import arguments - args = arguments.TreeArguments(self.evaluator, self, arglist) + args = arguments.TreeArguments(self.evaluator, self.parent_context, arglist) return [value for key, value in args.unpack() if key is None] else: return [LazyKnownContext(compiled.builtin_from_name(self.evaluator, u'object'))] diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index f5c1d892..5e7043f7 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -95,7 +95,26 @@ class NameFinder(object): def get_filters(self, search_global=False): origin_scope = self._get_origin_scope() if search_global: - return get_global_filters(self._evaluator, self._context, self._position, origin_scope) + position = self._position + + # For functions and classes the defaults don't belong to the + # function and get evaluated in the context before the function. So + # make sure to exclude the function/class name. + if origin_scope is not None: + ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef', 'lambdef') + lambdef = None + if ancestor == 'lambdef': + # For lambdas it's even more complicated since parts will + # be evaluated later. + lambdef = ancestor + ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef') + if ancestor is not None: + colon = ancestor.children[-2] + if position < colon.start_pos: + if lambdef is None or position < lambdef.children[-2].start_pos: + position = ancestor.start_pos + + return get_global_filters(self._evaluator, self._context, position, origin_scope) else: return self._context.get_filters(search_global, self._position, origin_scope=origin_scope) diff --git a/test/completion/classes.py b/test/completion/classes.py index 292cfc36..13e8ff95 100644 --- a/test/completion/classes.py +++ b/test/completion/classes.py @@ -422,17 +422,18 @@ class Super(object): a = 3 def return_sup(self): return 1 +SuperCopy = Super class TestSuper(Super): #? super() def test(self): - #? Super() + #? SuperCopy() super() #? ['a'] super().a if 1: - #? Super() + #? SuperCopy() super() def a(): #? @@ -446,6 +447,17 @@ class TestSuper(Super): TestSuper().return_sup() +Super = 3 + +class Foo(): + def foo(self): + return 1 +# Somehow overwriting the same name caused problems (#1044) +class Foo(Foo): + def foo(self): + #? int() + super().foo() + # ----------------- # if flow at class level # ----------------- diff --git a/test/completion/functions.py b/test/completion/functions.py index 893e4a39..bc4eb200 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -201,6 +201,9 @@ def default_function(a=default): #? int() default_function() +def default(a=default): + #? int() + a # ----------------- # closures