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

"from module import t" completion: include __all__ #1712

Open
mikez opened this issue Dec 18, 2020 · 9 comments
Open

"from module import t" completion: include __all__ #1712

mikez opened this issue Dec 18, 2020 · 9 comments
Labels

Comments

@mikez
Copy link

mikez commented Dec 18, 2020

Feature request:
Upon completing from module import t, add values in module.__all__ to names.

Background:
With the introduction of module __getattr__ and __dir__ in PEP562, I've found situations while coding where the autocompletion names can only be inferred from __all__ or __dir__.

Existing implementations in other contexts:

Past discussions:

Looking through the Jedi source code, I see no immediate simple way of solving this. If there's a way to write a custom extension or plugin for Jedi for my IDE that works for me too.

Viile dank für Jedi, Dave. 🙏

@mikez mikez changed the title Complete for "from module import t": include __all__ "from module import t" completion: include __all__ Dec 18, 2020
@davidhalter
Copy link
Owner

With the introduction of module getattr and dir in PEP562, I've found situations while coding where the autocompletion names can only be inferred from all or dir.

Can you give me examples of concrete open source code bases where this is the case?

Viile dank für Jedi, Dave.

:)

@mikez
Copy link
Author

mikez commented Dec 19, 2020

My use case is a private repository involving lazy-loading modules which are costly to load. I use this auto-complete a lot, so it's very beneficial for me.

Searching on larger repositories on Github, I did not find that many matches. It doesn't seem to be a common use case at this time.

I noticed three patterns in general:

  1. lazy loading
  2. deprecation situations (I filtered those out)
  3. cleaner API

Here's a list:

@davidhalter
Copy link
Owner

davidhalter commented Dec 19, 2020

I see. Thanks for the examples! IMO it would be fine to add it.

However: I won't do it. I have other priorities. So if nobody steps up I will close this feature request again. It's probably also not easy to do. :)

@mikez
Copy link
Author

mikez commented Dec 19, 2020

I appreciate the fast response and I understand; I also value prioritization

Maybe you have some pointers on custom modification for my IDE? I don't know Jedi that well yet. I've found out that In the Anaconda code for example it seems to call Script(...).completions(). If I can easily intercept the current line here with the from module import t<tab>, then I could use iPython's strategy here for completion.

@davidhalter
Copy link
Owner

then I could use iPython's strategy here for completion.

What is that?

@mikez
Copy link
Author

mikez commented Dec 21, 2020

@davidhalter It's here. This is not using static analysis. (BTW happy holidays 🎄, I'm heading to 🇨🇭 soon—home of the Jedi.)

@davidhalter
Copy link
Owner

Well, the truth is that they mostly use Jedi for that. This is just a fallback for people that don't want to use Jedi.

You could obviously do something like that, but it's not going to be easy to cover all the edge cases.

Maybe you have some pointers on custom modification for my IDE?

You could probably use Jedi on the last module between from <...> import and then check in that module how __all__ is defined. That's definitely a quickfix that will work mostly fine.

@mikez
Copy link
Author

mikez commented Dec 21, 2020

This is just a fallback for people that don't want to use Jedi.

Ah, interesting! Maybe I was looking at the wrong code. Fact is that if I type in from my_custom_module import <tab> in a vanilla iPython or Jupyter Notebook, then I see all the completions including __all__. This is not the case in Sublime using pure Jedi.

@davidhalter
Copy link
Owner

Fact is that if I type in from my_custom_module import in a vanilla iPython or Jupyter Notebook, then I see all the completions including __all__. This is not the case in Sublime using pure Jedi.

This is probably because one is purely static analysis and the other one has access to dir and other runtime inspections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants