This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Allow some auto imports to be relative and others absolute #6462
Labels
You can continue the conversation there. Go to discussion →
Hi - I have run into some frustrating behaviour with relative import suggestions. I hope this issue can be helpful.
When using a project that has multiple separate module hierarchies, it is impossible to configure the automatic imports in a way that is satisfactory.
The behaviour we want is that imports from the local module are imported relatively, and imports across modules are imported absolutely.
As far as I can tell, there is no way to get this behaviour, no matter what I set in
python.analysis.include
,python.analysis.exclude
andpython.analysis.extraPaths
.I should be able to specify which directories are expected on the python path at runtime, but this does not seem possible.
Environment data
Code Snippet
A minimal example can be found here: https://github.com/maxeonyx/pyimport-issue-minimal
To run the project, use:
Repro Steps
Clone the following repo: https://github.com/maxeonyx/pyimport-issue-minimal
Comment out your VSCode user settings so that they don't interfere with the workspace settings in this project.
Open the repo in VSCode.
Open
appsrc/appmodule/__main__.py
. Take the suggested action. The created import is not correctExpected behavior
Relative mode
The following imports should be inserted in
relative
import mode:Absolute mode
The following imports should be inserted in
absolute
import mode:Actual behavior
The following imports are what are actually inserted:
Relative mode:
The
...depsrc.sharedmodule.patterns
import is NOT correct as per mypython.analysis.*
settings.Absolute mode
This works correctly:
Note
Note that
...depsrc
is NOT expected to be on the python path at runtime. I have setpython.analysis.autoSearchPaths
tofalse
so the workspace root should not be one of the search paths.If we have the
from ...depsrc.sharedmodule.patterns import retry
version, when we run with the following command, we will getImportError: attempted relative import beyond top-level package
.The text was updated successfully, but these errors were encountered: