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

Suggest more sources for auto imports #291

Closed
Yura52 opened this issue Aug 27, 2020 · 6 comments
Closed

Suggest more sources for auto imports #291

Yura52 opened this issue Aug 27, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@Yura52
Copy link

Yura52 commented Aug 27, 2020

Hi! The feature that allows to import things automatically while typing is super cool! However, in my opinion, there is one case where it can be improved even further.

I experienced the issue when using the feature when using my library (as a third-party module): https://github.com/Yura52/zero
The library contains the zero/all.py module that is designed specifically for importing things without producing many lines. However, the auto-import feature suggests imports only from submodules (such as zero.io), where entities are actually implemented. Instead, I would prefer importing them from zero.all.

@heejaechang
Copy link
Contributor

currently, in the next release, "from m import *" form is not considered, but "from m import t as t" is considered when choosing what to show in completion for auto import.

but let me play with it and see how much it affects our auto-import experiences.

@jakebailey
Copy link
Member

jakebailey commented Sep 2, 2020

Note that the new heuristic wouldn't help for this case, as zero.all is not shorter (in length or module dots) than zero.io. Usually re-exports are things like "np.array is actually np.core.some._long_compiled_module", for example.

I'm not sure how libraries can clearly indicate that they are the intended way to use libraries, if that intended way is not just the top level module.

@heejaechang
Copy link
Contributor

heejaechang commented Sep 2, 2020

we show both actual definition and best 1 import alias, so zero.all will at least show up.

@ain-soph
Copy link

I agree with this issue. I think we should certainly improve it. Hope this issue priority could be more urgent.

@heejaechang heejaechang added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jan 15, 2022
@heejaechang
Copy link
Contributor

heejaechang commented Jan 18, 2022

now, "python.analysis.indexing" became a real option. Set "python.analysis.indexing": true to enable indexing which will improve auto-import experience.

Also, new hidden option "python.analysis.packageIndexDepths" is added which can be used as below to control how much get indexed.

"python.analysis.packageIndexDepths": [['sklearn', 2],['matplotlib', 2]],

by default, only 1 level module of third party libraries will be indexed, but now, you can use ["package name", module levels to be scanned] to control that.

if you put "" to package name, then that will affect all packages.

for your example, ["zero", 2] will make all.py to be picked up.

thank you

fix will be in the next release 2022.1.2

@bschnurr
Copy link
Member

This issue has been fixed in version 2022.1.3, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

6 participants