From c84ebba304c9f00ade27873ae1041fd2158eb898 Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Thu, 12 Feb 2026 00:12:48 +0530 Subject: [PATCH] fix: replace mutable default arguments in trainer.py Using mutable default arguments (e.g. `= []`) in Python function signatures is a well-known anti-pattern (W0102). The default list is shared across all calls, which can lead to unexpected behavior if the list is ever mutated in place. Replace `= []` with `= None` and add explicit `None` guards for `__move_components_to_device` and `__move_components_to_cpu`. --- finetune/trainer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/finetune/trainer.py b/finetune/trainer.py index 5746fee..a0709a9 100644 --- a/finetune/trainer.py +++ b/finetune/trainer.py @@ -713,7 +713,9 @@ class Trainer: else: raise ValueError(f"Invalid mixed precision: {self.args.mixed_precision}") - def __move_components_to_device(self, dtype, ignore_list: List[str] = []): + def __move_components_to_device(self, dtype, ignore_list: List[str] = None): + if ignore_list is None: + ignore_list = [] ignore_list = set(ignore_list) components = self.components.model_dump() for name, component in components.items(): @@ -723,7 +725,9 @@ class Trainer: self.components, name, component.to(self.accelerator.device, dtype=dtype) ) - def __move_components_to_cpu(self, unload_list: List[str] = []): + def __move_components_to_cpu(self, unload_list: List[str] = None): + if unload_list is None: + unload_list = [] unload_list = set(unload_list) components = self.components.model_dump() for name, component in components.items():