TRF039

Imports guarded by is_*_available() must be removed once nothing in the file uses them.

   
Default Enabled
Scope All models
Source mlinter/trf039.py
Show in terminal mlinter --rule TRF039

What it does

Finds if is_*_available(): import ... blocks (including combinations such as is_vision_available() and is_torch_available()) and flags the import when the name is referenced nowhere else in the file, including inside string type hints and __all__.

Why is this bad?

ruff’s unused-import check does not clean these up: the import is reachable, so the block looks fine on its own. Once a refactor no longer needs PIL.Image, torch, etc., the guarded import lingers as dead weight and a misleading signal about the file’s real dependencies.

Example

 if is_vision_available():
-    from PIL import Image

Suppressing this rule

Add a # trf-ignore: TRF039 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.