TRF016

do_* flags declared on a processor class must be referenced by overridden preprocess/_preprocess.

   
Default Enabled
Scope All models
Source mlinter/trf016.py
Show in terminal mlinter --rule TRF016

What it does

When an image_processing_*.py or video_processing_*.py class declares boolean do_* attributes (do_resize, do_rescale, do_normalize, do_convert_rgb, …) and overrides preprocess() or _preprocess(), checks each flag is still consumed there: referenced directly, delegated via super().preprocess/_preprocess(…, **kwargs), or – image processors only – forwarded through _preprocess_image_like_inputs/_prepare_image_like_inputs. do_sample_frames is exempt: the base preprocess() consumes it before _preprocess() runs.

Why is this bad?

A do_X the override never references is dead: setting do_X=False has no effect, the operation runs anyway, and per-call overrides silently break.

Example

 class AcmeVideoProcessor(BaseVideoProcessor):
     do_resize = True
     do_normalize = True

     def _preprocess(
         self,
         videos,
+        do_resize: bool,
+        do_normalize: bool,
         size,
         image_mean,
         image_std,
         **kwargs,
     ):
         for video in videos:
-            video = self.resize(video, size=size)
-            video = self.normalize(video, image_mean, image_std)
+            if do_resize:
+                video = self.resize(video, size=size)
+            if do_normalize:
+                video = self.normalize(video, image_mean, image_std)

Suppressing this rule

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