diff --git a/python-frontend/src/main/java/org/sonar/python/semantic/v2/ProjectLevelTypeTable.java b/python-frontend/src/main/java/org/sonar/python/semantic/v2/ProjectLevelTypeTable.java index 36497db2af..ef6d012962 100644 --- a/python-frontend/src/main/java/org/sonar/python/semantic/v2/ProjectLevelTypeTable.java +++ b/python-frontend/src/main/java/org/sonar/python/semantic/v2/ProjectLevelTypeTable.java @@ -67,8 +67,8 @@ public PythonType getType(List typeFqnParts) { if (parent instanceof ModuleType moduleType) { TypeWrapper typeWrapper = moduleType.members().get(part); if (typeWrapper instanceof LazyTypeWrapper lazyTypeWrapper && !lazyTypeWrapper.isResolved()) { - if (i == typeFqnParts.size() - 1 && !(lazyTypeWrapper.hasImportPath(String.join(".", typeFqnParts)))) { - // this is the name we are looking for, resolve it + if (i == typeFqnParts.size() - 1 && !fqnSameAsImportedPath(typeFqnParts, lazyTypeWrapper)) { + // this is the name we are looking for and its imported path is not the one we are trying to find, resolve it return typeWrapper.type(); } @@ -91,6 +91,10 @@ public PythonType getType(List typeFqnParts) { return parent; } + private static boolean fqnSameAsImportedPath(List typeFqnParts, LazyTypeWrapper lazyTypeWrapper) { + return lazyTypeWrapper.hasImportPath(String.join(".", typeFqnParts)); + } + /** * This method returns a module type for a given FQN, or unknown if it cannot be resolved. * It is to be used to retrieve modules referenced in the "from" clause of an "import from" statement, diff --git a/python-frontend/src/test/java/org/sonar/python/semantic/v2/ProjectLevelTypeTableTest.java b/python-frontend/src/test/java/org/sonar/python/semantic/v2/ProjectLevelTypeTableTest.java index 6f99607308..a7214a2c60 100644 --- a/python-frontend/src/test/java/org/sonar/python/semantic/v2/ProjectLevelTypeTableTest.java +++ b/python-frontend/src/test/java/org/sonar/python/semantic/v2/ProjectLevelTypeTableTest.java @@ -255,7 +255,7 @@ class lib: ... } @Test - void resolveCustomStub() { + void resolveStubsWithImportedModuleVariableDescriptor() { var symbolTable = ProjectLevelSymbolTable.empty(); var table = new ProjectLevelTypeTable(symbolTable);