Skip to content

Commit 3be011d

Browse files
SONARPY-1008 S5607 (IncompatibleOperandsCheck) should not raise on type annotations (#1119)
1 parent b97c921 commit 3be011d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

python-checks/src/main/java/org/sonar/python/checks/IncompatibleOperands.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.sonar.plugins.python.api.tree.BinaryExpression;
3434
import org.sonar.plugins.python.api.tree.Token;
3535
import org.sonar.plugins.python.api.tree.Tree;
36+
import org.sonar.plugins.python.api.tree.TypeAnnotation;
3637
import org.sonar.plugins.python.api.tree.UnaryExpression;
3738
import org.sonar.plugins.python.api.types.InferredType;
3839

@@ -92,6 +93,11 @@ private class IncompatibleOperandsVisitor extends BaseTreeVisitor {
9293
this.context = context;
9394
}
9495

96+
@Override
97+
public void visitTypeAnnotation(TypeAnnotation tree) {
98+
// avoid raising FPs on type annotations
99+
}
100+
95101
@Override
96102
public void visitBinaryExpression(BinaryExpression binaryExpression) {
97103
InferredType leftType = binaryExpression.leftOperand().type();

python-checks/src/test/resources/checks/incompatibleOperands/arithmetic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ def builtin_compliant():
7878
myvar += 2
7979

8080
not myvar # coverage
81+
82+
83+
def type_annotations():
84+
mode: "OpenBinaryMode" | "OpenTextMode"

0 commit comments

Comments
 (0)