diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c6c95656..f365c87c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,8 @@ Changelog - **Add** ``Script.get_context`` to get information where you currently are. +- Goto on a function/attribute in a class now goes to the definition in its + super class. - Big **Script API Changes**: - The line and column parameters of ``jedi.Script`` are now deprecated - ``completions`` deprecated, use ``complete`` instead diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 8b2958dd..a052b872 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -309,7 +309,22 @@ class Script(object): # executed by `foo()`, if we the cursor is after `)`. return self.infer(line, column, only_stubs=only_stubs, prefer_stubs=prefer_stubs) name = self._get_module_context().create_name(tree_name) - names = list(name.goto()) + + # Make it possible to goto the super class function/attribute + # definitions, when they are overwritten. + names = [] + if name.tree_name.is_definition() and name.parent_context.is_class(): + class_node = name.parent_context.tree_node + class_value = self._get_module_context().create_value(class_node) + mro = class_value.py__mro__() + next(mro) # Ignore the first entry, because it's the class itself. + for cls in mro: + names = cls.goto(tree_name.value) + if names: + break + + if not names: + names = list(name.goto()) if follow_imports: names = filter_follow_imports(names) diff --git a/test/completion/inheritance.py b/test/completion/inheritance.py new file mode 100644 index 00000000..d2b5de6f --- /dev/null +++ b/test/completion/inheritance.py @@ -0,0 +1,27 @@ + +class Super(object): + attribute = 3 + + def func(self): + return 1 + + class Inner(): + pass + + +class Sub(Super): + #? 13 Sub.attribute + def attribute(self): + pass + + #! 8 ['attribute = 3'] + def attribute(self): + pass + + #! 4 ['def func'] + func = 3 + #! 12 ['def func'] + class func(): ... + + #! 8 ['class Inner'] + def Inner(self): ...