TRF063
Model-local imports must not need backends beyond those the importing module’s exported objects declare.
| Default | Enabled |
| Scope | All models |
| Source | mlinter/trf063.py |
| Show in terminal | mlinter --rule TRF063 |
What it does
Follows every relative import a model file runs at import time and flags it when the imported files need a backend the importing file does not declare: through its base requirements, the weakest @requires among its __all__ objects, or an is_<backend>_available() guard. A modular_*.py file is checked through the files it generates.
Why is this bad?
The lazy module imports a file once its declared backends are installed. If that file imports a sibling that needs more, from transformers import * crashes in that environment: a vision-only processor importing a torchvision image processor breaks installs with Pillow but no torch.
Example
if is_vision_available():
- from .image_processing_acme import AcmeImageProcessorKwargs
+ from .image_processing_pil_acme import AcmeImageProcessorKwargs
@requires(backends=("vision",))
class AcmeProcessor(ProcessorMixin):
Suppressing this rule
Add a # trf-ignore: TRF063 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.
