question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

goto_definition does not handle decorators

See original GitHub issue

goto_definition does not handle decorated functions correctly. When executed on a wrapped function, you are taken to the wrapper function instead of the original function.

Here’s a simple example that will reproduce the bug:

from functools import wraps

def logged(f):
    # goto_definition directs here instead of the wrapped function
    @wraps(f)
    def wrapper(*args, **kwargs):
        print('Calling function {}'.format(f.__name__))
        f(*args, **kwargs)
    return wrapper


@logged
def add(x, y):
    return x + y

# When executing goto_definition with the cursor over "add" 
# I am taken to "wrapper"
print(add(2, 2))

It doesn’t make a difference whether or not functools.wraps is used.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sloriacommented, Jan 10, 2015

Thanks @davidhalter for the clarification.

I think the common case is that the user wants to go the wrapped function if it is decorated, and the definition if it is not decorated. If I wanted to go to the wrapper, I would just put my cursor on the decorator and run goto_definition. Is there a way to define a single keymapping to do this (i.e. always go to the definition of a function, sans wrappers)?

0reactions
davidhaltercommented, Nov 28, 2020

By default it’s <leader>d. You can also read the docs/README. Please make sure you have an up-to-date jedi-vim (and submodules).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does "Go To Definition" and ”Go to References" works in ...
Go to Definition: If a language supports it, you can go to the definition of a symbol by pressing F12. If you press...
Read more >
March 2022 (version 1.66) - Visual Studio Code
Learn what is new in the Visual Studio Code March 2022 Release (1.66) ... More visible source control decorators - Higher visibility using ......
Read more >
Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Your browser can ' t play this video. ... Quick Tip, we're going to see how we connect a mouse shortcut to the...
Read more >
Fix: VS Code Go to Definition Not Working - YouTube
Visual Studio Code (VS Code) is a very popular code editor among the developers of the world. This is due to it's awesome...
Read more >
Glossary — IronPython 2.7.2b1 documentation - Read the Docs
See the documentation for function definition for more about decorators. ... garbage collection: The process of freeing memory when it is not used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found