forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Unresolved import if sys.path modified in __init__.py #6241
Copy link
Copy link
Closed
Labels
area-lintingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Description
For projects that include external repos, it would be handy to insert the relative dependency paths ONLY when importing the necessary module.
Here is an example project layout:
Project root
+-- external repo/
+-- lib/
+-- config # defines Config class
+-- utils/
+-- mypackageA
+-- __init__.py
+-- app.py
main.py
In main.py, when an app instance that depends on the Config.py module in the external repo is created, the sys.path must include external repo/lib at the time of importing app:
from mypackageA import app
app.App()
Instead of setting the PYTHONPATH statically, an alternative is to modify sys.path in mypackageA.__init__.py by inserting paths to external repo/lib for the app module to import Config. However, vscode shows unresolved import warnings in this use case.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-lintingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug