Skip to content
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

Fix numpy go-to-definition by taking it off autoimport list for this case #447

Merged
merged 2 commits into from
Oct 3, 2023

Conversation

smacke
Copy link
Contributor

@smacke smacke commented Oct 1, 2023

When numpy is in the autoimport list, I think go to definition doesn't use the pure static strategy of jedi's goto and sees that, e.g., numpy.ones has __module__ set to numpy and uses that, while the static strategy correctly sees that ones is defined in numpy.core.numeric. To fix, in this PR we take everything off the jedi autoimport list before using goto for GTD, and we restore it once we're done.

Test plan: added a unit test that passes with this PR and fails without this PR.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement @smacke!

I left some minor suggestions for you, otherwise looks good to me.

pylsp/plugins/definition.py Show resolved Hide resolved
pylsp/plugins/definition.py Show resolved Hide resolved
test/plugins/test_definitions.py Outdated Show resolved Hide resolved
test/plugins/test_definitions.py Outdated Show resolved Hide resolved
@ccordoba12 ccordoba12 added this to the v1.8.1 milestone Oct 1, 2023
@ccordoba12 ccordoba12 added the enhancement New feature or request label Oct 1, 2023
@ccordoba12 ccordoba12 changed the title fix numpy gtd by taking it off autoimport list for this case Fix numpy go-to-definition by taking it off autoimport list for this case Oct 1, 2023
@smacke
Copy link
Contributor Author

smacke commented Oct 1, 2023

Thanks for the suggestions! Just pushed an update that uses them.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now, thanks @smacke!

I'll wait a couple of days to see if someone else wants to chime in, otherwise I'll merge.

@ccordoba12 ccordoba12 merged commit ccbf6cd into python-lsp:develop Oct 3, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants