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 ef6d012962..377f21957f 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,9 @@ 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 && !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 + if (shouldResolveImmediately(lazyTypeWrapper, typeFqnParts, i)) { + // We try to resolve the type of the member if it points to a different module. + // If it points to the same module, we try to resolve the submodule of the same name return typeWrapper.type(); } @@ -91,8 +92,8 @@ public PythonType getType(List typeFqnParts) { return parent; } - private static boolean fqnSameAsImportedPath(List typeFqnParts, LazyTypeWrapper lazyTypeWrapper) { - return lazyTypeWrapper.hasImportPath(String.join(".", typeFqnParts)); + private static boolean shouldResolveImmediately(LazyTypeWrapper lazyTypeWrapper, List typeFqnParts, int i) { + return i == typeFqnParts.size() - 1 && !(lazyTypeWrapper.hasImportPath(String.join(".", typeFqnParts))); } /**