TRF066
Use @requires for unconditional backend checks and declare only requirements additional to the file or class.
| Default | Enabled |
| Scope | Models added on or after 2026-10-29 |
| Source | mlinter/trf066.py |
| Show in terminal | mlinter --rule TRF066 |
What it does
Flags backends in @requires that repeat the file’s implicit requirements or, for a method, its enclosing class’s explicit requirements. Also flags requires_backends(...) if it could be written as a @requires decorator instead, and a @requires placed above @classmethod or @staticmethod. The cutoff exempts older models from everything except the misplaced decorator.
Why is this bad?
Repeating backend requirements obscures which dependencies a method actually adds. An unconditional check at the start of a function belongs in @requires(backends=...), which exposes dependency metadata and performs the check when the function is called. Keep requires_backends for conditional requirements. @requires wraps a plain function, so above @classmethod or @staticmethod it wraps the descriptor instead and every call raises TypeError: it must sit below them.
Example
# image_processing_pil_acme.py already requires vision.
-@requires(backends=("vision", "torch"))
+@requires(backends=("torch",))
class AcmeImageProcessorPil(PilBackend):
- @requires(backends=("torch",))
def post_process(self, outputs):
return outputs
+ @requires(backends=("scipy",))
def refine(self, outputs):
- requires_backends(self, ["scipy"])
return outputs
Suppressing this rule
Add a # trf-ignore: TRF066 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.
Allowlisted models
4 models are exempt from TRF066 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 4 allowlisted models
autotimm_backbonetimm_wrapperwav2vec2_with_lm
