-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go To Definition of decorated functions that get wrapped goes to the wrapping function #1638
Comments
It seems plausible that this is related to the environment changes alluded to in #1033, though that may be unrelated. While I appreciate that the underlying functionality here is part of Jedi, the repeated reappearance of this bug is a little frustrating. Does this project have any automated testing around this sort of thing? If not, would you be open to some? |
yes I'm seeing the same issue I'm using python plugin 2018.4.0, vscode 1.23.0 |
@PeterJCLaw more tests are always a good thing, so yes, we would accept them. |
@brettcannon I've just had a look at this and spotted that there are already some higher level integration tests (specifically src/test/definitions seems related) which I'd not spotted the last time I had a look :) It seems more useful to add a test to those, rather than trying to create an entirely new infrastructure, so I'll look at doing that for this test case instead. |
Specifically this covers some basic cases as well as the reproductions of microsoft#1638 and microsoft#1033 plus the variant of microsoft#1033 which always worked.
This fixes microsoft#1638 and simplifies the code (to what I believe that @davidhalter had in mind in microsoft#1033 (comment)). This change means that all of the test cases recently added to 'navigation.tests.ts' now pass, meaning that navigtion to the definition of functions works through imports and goes to the original function, even when that function is decorated.
Hrm, from what I can tell of looking at the results for a bunch of test cases, this issue appears to be a result of the change to using As I've got a branch with a bunch of test cases for this, I'll add the fix to that and open a PR. As a related point, I suspect that this means that the Note on the current implementation: the first call in Edited: a previous version was a little confused about which methods were used when. |
To be very clear about this, it occurs only if the decorator returns a wrapping object, e.g. this does not cause any issues: def identity(func):
return func
@identity
def spam():
pass |
@brettcannon to check my understanding of your clarification:
|
I tested across files like you did, I'm just saying that if the decorator doesn't modify the returned object there's no issue. |
… decoration (#1712) * Add baseline function definition navigation tests This provides a starting point for more interesting tests. * Add tests for current cases Specifically this covers some basic cases as well as the reproductions of #1638 and #1033 plus the variant of #1033 which always worked. * Make navigation to definitions follow imports This fixes #1638 and simplifies the code (to what I believe that @davidhalter had in mind in #1033 (comment)). This change means that all of the test cases recently added to 'navigation.tests.ts' now pass, meaning that navigtion to the definition of functions works through imports and goes to the original function, even when that function is decorated. * Add news entry for PR * Improve framing of this
This appears to be regression of https://github.com/DonJayamanne/pythonVSCode/issues/742
Environment data
Actual behavior
Navigating to definition of a decorated function shows the definition of the decorator.
Note: this only reproduces in a package and not in a single file.
In one sense I can see why this is happening -- the decorator is actually what the symbol in question really is. However, that is not a useful thing for an editor to do and I would much prefer to be shown the definition of the decorated function instead.
I believe this is also a regression as I've only noticed this behaviour recently (I think it started failing some time after the new year, but I'm not sure).
Expected behavior
(copied from https://github.com/DonJayamanne/pythonVSCode/issues/742)
Navigating to definition of a decorated function should show the function in question.
Steps to reproduce:
(copied from https://github.com/DonJayamanne/pythonVSCode/issues/742)
my_context_manager
function from either the import or the usage (I use Ctrl+Click, though F12 and the context menu also reproduce the issue)This issue shows up for both class- and function-based decorators and for both local and standard-library decorators.
Logs
None from either the Output pane or the developer tools
The text was updated successfully, but these errors were encountered: