TRF031
Output-like dataclasses in modeling files must inherit ModelOutput.
| Default | Enabled |
| Scope | Models added on or after 2026-06-20 |
| Source | mlinter/trf031.py |
| Show in terminal | mlinter --rule TRF031 |
What it does
In modeling_*.py and modular_*.py, flags a top-level @dataclass whose bases include nothing ending in Output, unless it has two or more mandatory fields – those are internal argument bundles, which ModelOutput rejects at runtime.
Why is this bad?
A plain output dataclass does not index like a tuple, does not survive return_dict=False, and is invisible to @auto_docstring, so its fields never reach the generated API docs. ModelOutput gets all three for free.
Example
@auto_docstring
@dataclass
-class AcmeStructureOutput:
+class AcmeStructureOutput(ModelOutput):
positions: torch.Tensor
confidence: Optional[torch.Tensor] = None
Suppressing this rule
Add a # trf-ignore: TRF031 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.
