-
Notifications
You must be signed in to change notification settings - Fork 133
Unresolved import when opening a subdirectory of an import root as the workspace root #1060
Comments
There are two issues with this workspace:
which defines workspace root as
|
Hi Alexander,
Would moving the workspace file out of the library, up one level, have the same effect?
Could you be more specific about what part is incorrect in the example file? The link to PEP8 mentions that modules and packages should have short, lower case names, and the myLib example file clearly has an upper case 'L'. Is it that the cause of imports being unresolved? Is it the structure of import e.g. |
Yes
It may be the case. In your example, imports are unresolved because of the |
Thanks @AlexanderSher. Unfortunately, changing I'll take a look at the link you provided and tidy things up tomorrow and report back. |
|
Yes.
|
All the standard libraries are giving me IMHO this bug should be very high in the priority list. I certainly can't work with the language server in these conditions. Fortunately there is jedi as a backup. |
Seems to be related to #1156 |
@Anti-Distinctlyminty, we had several improvements recently. Can you try the daily build "python.analysis.downloadChannel": "daily"? |
@egabrum, your bug is most likely different from what @Anti-Distinctlyminty had. If you still have it on "python.analysis.downloadChannel": "daily" channel, can you please file a separate bug? |
@AlexanderSher I put The behaviour is still quite strange as shown here If I import |
Language server version is unrelated to extension version. It is displayed in the output on startup. Something like 0.3.x |
Thanks @MikhailArkhipov , here it is... |
You have a |
Thanks! that works! |
It's not a straightforward problem, |
I didn't mean to add the paths by itself, but to determinate "oh, i'm on this path, so this import must refer to that file". |
If it were that simple, we'd probably be doing it, but that's unfortunately not how Python's going to go load the code either.
All of these mean we have to make tradeoffs for what behavior we want/can feasibly do; we could be very, very loose, but then you may go to run the code and it break and you'd wonder why the editor didn't tell you something was wrong beforehand. |
I'm sorry, but I'm at a loss. I've "python.analysis.downloadChannel": "daily" enabled and a bunch of packages installed as editable installs.
I can't publish all this code and it could take me a some time to abstract it, making sure that the same behavior is still reproduced. The worst part is the inconsistent behavior. Maybe the language server has additional requirements for the way the components of a package are imported in the init.py within the package? Something that the interpreter and Jedi tolerate, but the language server is more picky about? |
I also tested this again with the simple myLib example files in the original report. |
EDIT: No, it's not, sorry. That sounds like something different where something's location is lost and set to the default. |
That original example doesn't work, no... It's using a VS Code workspace to make a project appear to have a folder called myLib, when it actually doesn't. VS Code tells us the root is the folder that's opened, which is With our current import resolver (which places the workspace root as the first import root), I'm not sure how we could make this work. All other scenarios we've looked at involve code in different folders inside the workspace; trying to open a subfolder and then import above (or make the workspace "look" like there are more folders than there actually are) seems really tricky to get right. |
Post edited: unrelated. |
Thanks @jakebailey |
@Anti-Distinctlyminty commented on Mon May 06 2019
Environment data
Expected behaviour
With
python.autoComplete.extraPaths
set correctly, modules should import without issue.Actual behaviour
I receive a

Unresolved import 'moduleName'
when using syntax of the formimport workspace_folder.module as alt_name
and if the .code-workspace file is in the same directory.
e.g.
Steps to reproduce:
myLib.zip
python.autoComplete.extraPaths
to the folder containing myLib.import myLib.importMe as im
has an unresolved import error.I am aware that the organization of this workspace is sub-optimal, with the code-workspace file being inside the python library folder. However, with all paths being set correctly, the import should still succeed.
Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Blank.
Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)Blank.
The text was updated successfully, but these errors were encountered: