Skip to content

Commit 920bf3a

Browse files
SONARPY-1866 Infer types of reassigned parameters even when they don't have type annotations (#1809)
1 parent c63eae2 commit 920bf3a

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ private void inferTypesAndMemberAccessSymbols(FileInput fileInput) {
8888

8989
private void inferTypesAndMemberAccessSymbols(FunctionDef functionDef) {
9090
Set<Name> parameterNames = TreeUtils.nonTupleParameters(functionDef).stream()
91-
// TODO SONARPY-1866: it probably doesn't make sense to restrict to annotated parameters here
92-
.filter(parameter -> parameter.typeAnnotation() != null)
9391
.map(Parameter::name)
9492
.collect(Collectors.toSet());
9593
Set<SymbolV2> localVariables = symbolTable.getSymbolsByRootTree(functionDef);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def foo(param):
377377

378378
var functionDef = (FunctionDef) root.statements().statements().get(0);
379379
var lastExpressionStatement = (ExpressionStatement) functionDef.body().statements().get(functionDef.body().statements().size() -1);
380-
Assertions.assertThat(lastExpressionStatement.expressions().get(0).typeV2().unwrappedType()).isEqualTo(PythonType.UNKNOWN);
380+
Assertions.assertThat(lastExpressionStatement.expressions().get(0).typeV2().unwrappedType()).isEqualTo(STR_TYPE);
381381
}
382382

383383
@Test

0 commit comments

Comments
 (0)