TRF003

forward() should use capture_output/can_return_tuple decorators instead of manual return_dict branching.

   
Default Disabled
Scope All models
Source mlinter/trf003.py
Show in terminal mlinter --rule TRF003

What it does

Detects forward methods that use the old ‘if not return_dict: return (x,)’ pattern.

Why is this bad?

The old return_dict branching pattern is error-prone and verbose. Use the capture_output or can_return_tuple decorators instead.

Example

-def forward(self, x, return_dict=None):
-    if not return_dict:
-        return (x,)
-    return AcmeModelOutput(last_hidden_state=x)
+@can_return_tuple
+def forward(self, x):
+    return AcmeModelOutput(last_hidden_state=x)

Enabling this rule

TRF003 is off by default. Turn it on for a run with:

mlinter --enable-rules TRF003

Suppressing this rule

Add a # trf-ignore: TRF003 comment on the flagged line or the line directly above it. See Suppressing rules for whole-file directives and when a suppression is the wrong answer.