You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
PLS doesn't flag error in a relative import if it is found in another root directory #509
The analyzer incorrectly accepts relative imports in cases where the path is relative to a root but not to the importing file.
Consider the following case:
Directory structure:
src
|->module
|--->init.py
test.py
PYTHONPATH=src
test.py contains the following code:
from .module import Foo
This import should be flagged as invalid because the path ".module" should be relative to the test.py file. However, the code in PathResolverSnapshot.GetImportsFromRelativePath considers all of the root search directories when it performs its search. It therefore finds an import match when it shouldn't.
I think the problem is in PathResolverSnapshot.RootContains. It doesn't do anything to validate that the specified lastEdge starts in the same location as the root. If the relative path happens to match items within that root, the method returns true. If the relative path is zero length, all roots return true.
A proposed fix is to add the following piece of code to PathResolverSnapshot.RootContains before the while loop:
Activity
AlexanderSher commentedon Dec 31, 2018
The problem isn't related to the multiple roots. With
"python.autoComplete.extraPaths": ["path_to_folder/src"]and the following file structure:code
from .module import *intest.pyis valid.But,
from .moduleis invalid whentest.pyis in root, no matter if we havemoduleor not.AlexanderSher commentedon Dec 31, 2018
We probably should have an exception for the working directory, cause it can be a top directory of the module.
- Fix microsoft#509: PLS doesn't flag error in a relative import if i…
Two path resolution bug fixes
Two path resolution bug fixes
Cherry pick fixes from Release branch into PTVS branch (#578)