31
31
import org .sonar .plugins .python .api .tree .Name ;
32
32
import org .sonar .plugins .python .api .tree .QualifiedExpression ;
33
33
import org .sonar .plugins .python .api .tree .Tree ;
34
- import org .sonar .python .cfg .fixpoint .ReachingDefinitionsAnalysis ;
35
34
import org .sonar .python .tree .TreeUtils ;
36
35
37
36
@ Rule (key = "S6982" )
@@ -40,13 +39,9 @@ public class TorchModuleModeShouldBeSetAfterLoadingCheck extends PythonSubscript
40
39
private static final String LOAD_STATE_DICT_NAME = "load_state_dict" ;
41
40
private static final String MESSAGE = "Set the module in training or evaluation mode." ;
42
41
43
- private ReachingDefinitionsAnalysis reachingDefinitionsAnalysis ;
44
42
45
43
@ Override
46
44
public void initialize (Context context ) {
47
- context .registerSyntaxNodeConsumer (Tree .Kind .FILE_INPUT , ctx -> reachingDefinitionsAnalysis =
48
- new ReachingDefinitionsAnalysis (ctx .pythonFile ()));
49
-
50
45
context .registerSyntaxNodeConsumer (Tree .Kind .CALL_EXPR , ctx -> {
51
46
CallExpression callExpr = (CallExpression ) ctx .syntaxNode ();
52
47
List <Usage > receiverUsages = getForwardUsagesOfReceiver (callExpr );
@@ -56,7 +51,7 @@ public void initialize(Context context) {
56
51
});
57
52
}
58
53
59
- private boolean isLoadStateDictCall (CallExpression callExpr ) {
54
+ private static boolean isLoadStateDictCall (CallExpression callExpr ) {
60
55
// To properly check if the correct load_state_dict is called, typeshed type information would be required.
61
56
// Since this is currently not possible, we check if the parameter to load_state_dict is torch.load(...),
62
57
// with the assumption that if torch.load is passed to this load_state_dict, it is probably the correct method
0 commit comments