Import from __init__.py instead of full imports #4680
Replies: 1 comment 1 reply
-
I see this is 3 weeks old and figured I'd spark a discussion. I have not had cases like this yet, that I have been keen enough to realize personally I usually just accept whatever import(s) is suggested and works without questioning the suggestion(s). I assume most developers tend to accept suggestion(s), without question(s) like myself. (as long as there is no visible or functional issues / errors) I do see where this could help others and possibly myself in the future from any confusion and improve VSCode. I'm not aware of how these suggestions are curated at this moment but I did not see any identifiers when I did a quick little test which usually display when using suggestions from other utilities so it very well could be an issue with VSCode. What I am curious about is if this has any actual impacts other than simplicity and straightforwardness. That actually affect performance or other factors? I feel like this would take more testing than anyone cares to do, but it does make me curious to know if it makes a difference based on how the import is formatted. Maybe someone with a better understanding of how this actually works would be able to elaborate on this. |
Beta Was this translation helpful? Give feedback.
-
I have a python project in vscode. Suppose this is my file structure:
File
foo.py
defines a classFoo
, andfoo/__init__.py
imports it and declares it in__all__
like this:Now in
bar.py
I would like to importFoo
like this:But when VSCode suggests the import, it only suggests it as:
Is there any way to make vscode recognize that the shorter import exists and suggest it? It does accept the shorter import as valid when I type it out myself, but it never imports things like that on its own.
Beta Was this translation helpful? Give feedback.
All reactions