Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Seppli11 committed Nov 26, 2024
1 parent f280073 commit 67a7072
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.sonar.plugins.python.api.tree.StatementList;
import org.sonar.plugins.python.api.tree.Tree;
import org.sonar.python.semantic.SymbolUtils;
import org.sonar.python.semantic.v2.types.AstBasedPropagation;
import org.sonar.python.semantic.v2.types.AstBasedTypeInference;
import org.sonar.python.semantic.v2.types.FlowSensitiveTypeInference;
import org.sonar.python.semantic.v2.types.Propagation;
import org.sonar.python.semantic.v2.types.PropagationVisitor;
Expand Down Expand Up @@ -123,8 +123,8 @@ private Map<SymbolV2, Set<PythonType>> inferTypesAndMemberAccessSymbols(Tree sco
statements.accept(tryStatementVisitor);
if (tryStatementVisitor.hasTryStatement()) {
// CFG doesn't model precisely try-except statements. Hence we fallback to AST based type inference
return new AstBasedPropagation(propagationVisitor.propagationsByLhs(), projectLevelTypeTable)
.processPropagations(getTrackedVars(declaredVariables, assignedNames));
return new AstBasedTypeInference(propagationVisitor.propagationsByLhs(), projectLevelTypeTable)
.process(getTrackedVars(declaredVariables, assignedNames));
}

ControlFlowGraph cfg = controlFlowGraphSupplier.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
import org.sonar.python.types.v2.PythonType;
import org.sonar.python.types.v2.UnionType;

public class AstBasedPropagation {
public class AstBasedTypeInference {
private final Map<SymbolV2, Set<Propagation>> propagationsByLhs;
private final Propagator propagator;

public AstBasedPropagation(Map<SymbolV2, Set<Propagation>> propagationsByLhs, TypeTable typeTable) {
public AstBasedTypeInference(Map<SymbolV2, Set<Propagation>> propagationsByLhs, TypeTable typeTable) {
this.propagationsByLhs = propagationsByLhs;
this.propagator = new Propagator(typeTable);
}

public Map<SymbolV2, Set<PythonType>> processPropagations(Set<SymbolV2> trackedVars) {
public Map<SymbolV2, Set<PythonType>> process(Set<SymbolV2> trackedVars) {
computePropagationDependencies(trackedVars);

Set<SymbolV2> initializedVars = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ private boolean isNumber(PythonType type) {
}

private static PythonType toObjectType(PythonType type) {
if (type instanceof ObjectType || type == PythonType.UNKNOWN) {
if (type == PythonType.UNKNOWN) {
return type;
} else if(type instanceof ObjectType objectType) {
return new ObjectType(objectType.typeWrapper(), objectType.attributes(), objectType.members(), objectType.typeSource());
}
return new ObjectType(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,6 @@ void unary_expression_of_variables(String code, PythonType expectedType) {
assertThat(lastExpression(code).typeV2()).isInstanceOf(ObjectType.class).extracting(PythonType::unwrappedType).isEqualTo(expectedType);
}


@ParameterizedTest
@MethodSource("unary_expression_of_variables")
void unary_expression_of_variables_with_try_except(String code, PythonType expectedType) {
Expand Down

0 comments on commit 67a7072

Please sign in to comment.