Skip to content

Commit

Permalink
SONARPY-2219 Fix tests importing variable which FQN starts the same a…
Browse files Browse the repository at this point in the history
…s module FQN
  • Loading branch information
thomas-serre-sonarsource committed Oct 21, 2024
1 parent 10f3507 commit a6d4ada
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
Expand All @@ -45,6 +47,7 @@
import org.sonar.python.semantic.v2.SymbolTableBuilderV2;
import org.sonar.python.semantic.v2.SymbolV2;
import org.sonar.python.semantic.v2.TypeInferenceV2;
import org.sonar.python.semantic.v2.UsageV2;
import org.sonar.python.semantic.v2.converter.PythonTypeToDescriptorConverter;
import org.sonar.python.semantic.v2.typeshed.TypeShedDescriptorsProvider;
import org.sonar.python.types.v2.PythonType;
Expand Down Expand Up @@ -228,7 +231,14 @@ public void addModuleV2(String fullyQualifiedModuleName, Set<Descriptor> moduleD
public void addModuleV2(String fullyQualifiedModuleName, Map<SymbolV2, Set<PythonType>> typesBySymbol) {
var moduleDescriptors = typesBySymbol.entrySet()
.stream()
.map(entry -> pythonTypeToDescriptorConverter.convert(fullyQualifiedModuleName, entry.getKey(), entry.getValue()))
.map(entry -> {
var descriptor = pythonTypeToDescriptorConverter.convert(fullyQualifiedModuleName, entry.getKey(), entry.getValue());
return Map.entry(entry.getKey(), descriptor);
}
)
.filter( entry -> !(!entry.getValue().fullyQualifiedName().startsWith(fullyQualifiedModuleName)
|| entry.getKey().usages().stream().anyMatch(u -> u.kind().equals(UsageV2.Kind.IMPORT))))
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
addModuleV2(fullyQualifiedModuleName, moduleDescriptors);
}
Expand Down

0 comments on commit a6d4ada

Please sign in to comment.