Skip to content

Commit 0168c31

Browse files
ghislainpiotguillaume-dequenne
authored andcommitted
SONARPY-2177 ProjectLevelTypeTable#getType should stop trying to look in ObjectType for members
1 parent e946c69 commit 0168c31

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

python-frontend/src/main/java/org/sonar/python/semantic/v2/ProjectLevelTypeTable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.stream.IntStream;
2626
import org.sonar.python.semantic.ProjectLevelSymbolTable;
2727
import org.sonar.python.types.v2.ModuleType;
28+
import org.sonar.python.types.v2.ObjectType;
2829
import org.sonar.python.types.v2.PythonType;
2930

3031
public class ProjectLevelTypeTable {
@@ -65,6 +66,9 @@ public PythonType getType(List<String> typeFqnParts) {
6566
var parent = (PythonType) rootModule;
6667
for (int i = 0; i < typeFqnParts.size(); i++) {
6768
var part = typeFqnParts.get(i);
69+
if (parent instanceof ObjectType) {
70+
return PythonType.UNKNOWN;
71+
}
6872
Optional<PythonType> resolvedMember = parent.resolveMember(part);
6973
if (resolvedMember.isPresent()) {
7074
parent = resolvedMember.get();

python-frontend/src/test/java/org/sonar/python/semantic/v2/TypeInferenceV2Test.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,16 @@ void basic_imported_symbols() {
23562356
assertThat(((UnionType) mathModule.resolveMember("acos").get()).candidates()).allMatch(FunctionType.class::isInstance);
23572357
}
23582358

2359+
@Test
2360+
// TODO SONARPY-2176 ProjectLevelSymbolTable#getType should be able to resolve types when there is a conflict between a member and a subpackage
2361+
void import_conflict_between_member_and_submodule() {
2362+
var statement = lastExpression("""
2363+
import opentracing.tracer.Tracer as ottt
2364+
ottt
2365+
""");
2366+
assertThat(statement.typeV2()).isInstanceOf(UnknownType.class);
2367+
}
2368+
23592369
@Test
23602370
void isInstanceTests() {
23612371
var xType = lastExpression("""

0 commit comments

Comments
 (0)