Skip to content

Commit 673eb19

Browse files
authored
NO-JIRA: Fix quality gate issue (#1985)
1 parent 312f89c commit 673eb19

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.sonar.plugins.python.api.tree.Name;
3232
import org.sonar.plugins.python.api.tree.QualifiedExpression;
3333
import org.sonar.plugins.python.api.tree.Tree;
34-
import org.sonar.python.cfg.fixpoint.ReachingDefinitionsAnalysis;
3534
import org.sonar.python.tree.TreeUtils;
3635

3736
@Rule(key = "S6982")
@@ -40,13 +39,9 @@ public class TorchModuleModeShouldBeSetAfterLoadingCheck extends PythonSubscript
4039
private static final String LOAD_STATE_DICT_NAME = "load_state_dict";
4140
private static final String MESSAGE = "Set the module in training or evaluation mode.";
4241

43-
private ReachingDefinitionsAnalysis reachingDefinitionsAnalysis;
4442

4543
@Override
4644
public void initialize(Context context) {
47-
context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, ctx -> reachingDefinitionsAnalysis =
48-
new ReachingDefinitionsAnalysis(ctx.pythonFile()));
49-
5045
context.registerSyntaxNodeConsumer(Tree.Kind.CALL_EXPR, ctx -> {
5146
CallExpression callExpr = (CallExpression) ctx.syntaxNode();
5247
List<Usage> receiverUsages = getForwardUsagesOfReceiver(callExpr);
@@ -56,7 +51,7 @@ public void initialize(Context context) {
5651
});
5752
}
5853

59-
private boolean isLoadStateDictCall(CallExpression callExpr) {
54+
private static boolean isLoadStateDictCall(CallExpression callExpr) {
6055
// To properly check if the correct load_state_dict is called, typeshed type information would be required.
6156
// Since this is currently not possible, we check if the parameter to load_state_dict is torch.load(...),
6257
// with the assumption that if torch.load is passed to this load_state_dict, it is probably the correct method

0 commit comments

Comments
 (0)