goto_definition does not handle decorators
See original GitHub issuegoto_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:
- Created 9 years ago
- Comments:16 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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)?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).