Skip to content

fix: replace mutable default arguments in trainer.py#812

Open
Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Mr-Neutr0n:fix/mutable-default-arguments
Open

fix: replace mutable default arguments in trainer.py#812
Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Mr-Neutr0n:fix/mutable-default-arguments

Conversation

@Mr-Neutr0n
Copy link
Copy Markdown

Summary

  • Replace mutable default argument = [] with = None in __move_components_to_device (line 716) and __move_components_to_cpu (line 726) in finetune/trainer.py
  • Add explicit if ... is None: ... = [] guards before usage

Using mutable default arguments in Python function signatures is a well-known anti-pattern (PylintW0102). The default list object is created once at function definition time and shared across all calls, so any in-place mutation would persist between invocations. Replacing with None and guarding ensures a fresh list is created on each call.

Test plan

  • Verified the diff only touches the two target signatures and adds None guards
  • No behavioral change when callers pass an explicit list
  • No behavioral change when callers omit the argument (empty list is created fresh each time)

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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant