Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions its/ruling/src/test/resources/expected/python-S1656.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,17 @@
278,
289,
],
'project:tensorflow/python/autograph/pyct/ast_util.py':[
171,
],
'project:tensorflow/python/autograph/pyct/static_analysis/reaching_definitions_test.py':[
170,
171,
],
'project:tensorflow/python/autograph/pyct/templates.py':[
213,
],
'project:tensorflow/python/keras/distribute/keras_correctness_test_base.py':[
611,
],
'project:tensorflow/python/kernel_tests/conv1d_transpose_test.py':[
129,
254,
],
'project:tensorflow/python/ops/script_ops.py':[
525,
],
'project:tensorflow/python/training/tracking/tracking_test.py':[
60,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.sonar.plugins.python.api.tree.AssignmentStatement;
import org.sonar.plugins.python.api.tree.CallExpression;
import org.sonar.plugins.python.api.tree.Expression;
import org.sonar.plugins.python.api.tree.ExpressionList;
import org.sonar.plugins.python.api.tree.ImportFrom;
import org.sonar.plugins.python.api.tree.ImportName;
import org.sonar.plugins.python.api.tree.Name;
Expand Down Expand Up @@ -58,7 +59,7 @@ public void initialize(Context context) {
context.registerSyntaxNodeConsumer(Tree.Kind.IMPORT_NAME, ctx ->
((ImportName) ctx.syntaxNode()).modules().forEach(this::addImportedName));

context.registerSyntaxNodeConsumer(Tree.Kind.ASSIGNMENT_STMT, this::checkAssignement);
context.registerSyntaxNodeConsumer(Tree.Kind.ASSIGNMENT_STMT, this::checkAssignment);

context.registerSyntaxNodeConsumer(Tree.Kind.ANNOTATED_ASSIGNMENT, this::checkAnnotatedAssignment);

Expand All @@ -72,12 +73,12 @@ private static void checkAssignmentExpression(SubscriptionContext ctx) {
}
}

private void checkAssignement(SubscriptionContext ctx) {
private void checkAssignment(SubscriptionContext ctx) {
AssignmentStatement assignment = (AssignmentStatement) ctx.syntaxNode();
Expression assignedValue = assignment.assignedValue();
for (int i = 0; i < assignment.lhsExpressions().size(); i++) {
List<Expression> expressions = assignment.lhsExpressions().get(i).expressions();
if (expressions.size() == 1 && CheckUtils.areEquivalent(assignedValue, expressions.get(0)) && !isException(assignment, assignedValue)) {
ExpressionList expressionList = assignment.lhsExpressions().get(i);
if (expressionList.commas().isEmpty() && CheckUtils.areEquivalent(assignedValue, expressionList.expressions().get(0)) && !isException(assignment, assignedValue)) {
ctx.addIssue(assignment.equalTokens().get(i), MESSAGE);
}
}
Expand Down
6 changes: 6 additions & 0 deletions python-checks/src/test/resources/checks/selfAssignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ def assignment_expression():
pass
if (b:=foo()):
b = b # Noncompliant

def unpacking():
x = [1]
x, = x # OK
y, = x = x # Noncompliant
# ^