jedi-vim: goto_definition does not handle decorators
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.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (6 by maintainers)
Commits related to this issue
- Set follow_imports=True in goto_assignments goto_assignments now handles decorators correctly. See: davidhalter/jedi-vim#348 and davidhalter/jedi-vim#494 — committed to yangle/jedi-vim by yangle 7 years ago
- Set follow_imports=True in goto_assignments goto_assignments now handles decorators correctly. See: davidhalter/jedi-vim#348 and davidhalter/jedi#494 — committed to yangle/jedi-vim by yangle 7 years ago
- Set follow_imports=True in goto_assignments goto_assignments now handles decorators correctly. See: davidhalter/jedi-vim#348 and davidhalter/jedi#494 — committed to mwhite/jedi-vim by yangle 7 years ago
- Set follow_imports=True in goto_assignments goto_assignments now handles decorators correctly. See: davidhalter/jedi-vim#348 and davidhalter/jedi#494 — committed to yangle/jedi-vim by yangle 7 years ago
- Set follow_imports=True in goto_assignments goto_assignments now handles decorators correctly. See: davidhalter/jedi-vim#348 and davidhalter/jedi#494 — committed to yangle/jedi-vim by yangle 7 years ago
- Set follow_imports=True in goto_assignments goto_assignments now handles decorators correctly. See: davidhalter/jedi-vim#348 and davidhalter/jedi#494 — committed to yangle/jedi-vim by yangle 7 years ago
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)?