3131import org .sonar .plugins .python .api .tree .Name ;
3232import org .sonar .plugins .python .api .tree .QualifiedExpression ;
3333import org .sonar .plugins .python .api .tree .Tree ;
34- import org .sonar .python .cfg .fixpoint .ReachingDefinitionsAnalysis ;
3534import 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