TRF003
forward() should use @capture_output/@can_return_tuple, not manual return_dict branching.
| Default | Disabled |
| Scope | All models |
| Source | mlinter/trf003.py |
| Show in terminal | mlinter --rule TRF003 |
What it does
Flags the old if not return_dict: return (x,) pattern in forward.
Why is this bad?
Manual return_dict branching is verbose and easy to get wrong. Let @capture_output or @can_return_tuple do it.
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.
