fix: replace mutable default arguments in trainer.py#812
Open
Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Open
fix: replace mutable default arguments in trainer.py#812Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Mr-Neutr0n wants to merge 1 commit intozai-org:mainfrom
Conversation
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
= []with= Nonein__move_components_to_device(line 716) and__move_components_to_cpu(line 726) infinetune/trainer.pyif ... is None: ... = []guards before usageUsing 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
Noneand guarding ensures a fresh list is created on each call.Test plan
Noneguards