Skip to content

Commit 67a7072

Browse files
committed
fixes after review
1 parent f280073 commit 67a7072

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.sonar.plugins.python.api.tree.StatementList;
3535
import org.sonar.plugins.python.api.tree.Tree;
3636
import org.sonar.python.semantic.SymbolUtils;
37-
import org.sonar.python.semantic.v2.types.AstBasedPropagation;
37+
import org.sonar.python.semantic.v2.types.AstBasedTypeInference;
3838
import org.sonar.python.semantic.v2.types.FlowSensitiveTypeInference;
3939
import org.sonar.python.semantic.v2.types.Propagation;
4040
import org.sonar.python.semantic.v2.types.PropagationVisitor;
@@ -123,8 +123,8 @@ private Map<SymbolV2, Set<PythonType>> inferTypesAndMemberAccessSymbols(Tree sco
123123
statements.accept(tryStatementVisitor);
124124
if (tryStatementVisitor.hasTryStatement()) {
125125
// CFG doesn't model precisely try-except statements. Hence we fallback to AST based type inference
126-
return new AstBasedPropagation(propagationVisitor.propagationsByLhs(), projectLevelTypeTable)
127-
.processPropagations(getTrackedVars(declaredVariables, assignedNames));
126+
return new AstBasedTypeInference(propagationVisitor.propagationsByLhs(), projectLevelTypeTable)
127+
.process(getTrackedVars(declaredVariables, assignedNames));
128128
}
129129

130130
ControlFlowGraph cfg = controlFlowGraphSupplier.get();

python-frontend/src/main/java/org/sonar/python/semantic/v2/types/AstBasedPropagation.java renamed to python-frontend/src/main/java/org/sonar/python/semantic/v2/types/AstBasedTypeInference.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@
4242
import org.sonar.python.types.v2.PythonType;
4343
import org.sonar.python.types.v2.UnionType;
4444

45-
public class AstBasedPropagation {
45+
public class AstBasedTypeInference {
4646
private final Map<SymbolV2, Set<Propagation>> propagationsByLhs;
4747
private final Propagator propagator;
4848

49-
public AstBasedPropagation(Map<SymbolV2, Set<Propagation>> propagationsByLhs, TypeTable typeTable) {
49+
public AstBasedTypeInference(Map<SymbolV2, Set<Propagation>> propagationsByLhs, TypeTable typeTable) {
5050
this.propagationsByLhs = propagationsByLhs;
5151
this.propagator = new Propagator(typeTable);
5252
}
5353

54-
public Map<SymbolV2, Set<PythonType>> processPropagations(Set<SymbolV2> trackedVars) {
54+
public Map<SymbolV2, Set<PythonType>> process(Set<SymbolV2> trackedVars) {
5555
computePropagationDependencies(trackedVars);
5656

5757
Set<SymbolV2> initializedVars = new HashSet<>();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ private boolean isNumber(PythonType type) {
8989
}
9090

9191
private static PythonType toObjectType(PythonType type) {
92-
if (type instanceof ObjectType || type == PythonType.UNKNOWN) {
92+
if (type == PythonType.UNKNOWN) {
9393
return type;
94+
} else if(type instanceof ObjectType objectType) {
95+
return new ObjectType(objectType.typeWrapper(), objectType.attributes(), objectType.members(), objectType.typeSource());
9496
}
9597
return new ObjectType(type);
9698
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,6 @@ void unary_expression_of_variables(String code, PythonType expectedType) {
26332633
assertThat(lastExpression(code).typeV2()).isInstanceOf(ObjectType.class).extracting(PythonType::unwrappedType).isEqualTo(expectedType);
26342634
}
26352635

2636-
26372636
@ParameterizedTest
26382637
@MethodSource("unary_expression_of_variables")
26392638
void unary_expression_of_variables_with_try_except(String code, PythonType expectedType) {

0 commit comments

Comments
 (0)