Replace mutable default list with None sentinel in basic_collation_fn#84
Open
lonexreb wants to merge 1 commit intoNVlabs:mainfrom
Open
Replace mutable default list with None sentinel in basic_collation_fn#84lonexreb wants to merge 1 commit intoNVlabs:mainfrom
lonexreb wants to merge 1 commit intoNVlabs:mainfrom
Conversation
Mutable default arguments are a well-known Python pitfall: the empty list is created once at function definition and reused across every call, so any mutation persists across calls. While the current body only iterates over `unstackable_keys` (no mutation), keeping the mutable default makes the function fragile to future edits and silently warned by linters (ruff B006). Switch to the standard `list[str] | None = None` pattern and treat None as "no extra unstackable keys" via `unstackable_keys or []` at the iteration site. Behavior is unchanged. Signed-off-by: lonexreb <[email protected]>
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.
Problem
basic_collation_fninsrc/alpamayo_r1/processor/qwen_processor.pyuses a mutable list as the default forunstackable_keys:Mutable default arguments are a well-known Python pitfall — the empty list is created once at function-definition time and reused across every call, so any mutation persists across invocations. Even though the current body only iterates over the argument (no mutation today), this pattern is brittle to future edits and is flagged by
ruff B006/pylint W0102.Fix
Switch to the standard
list[str] | None = Nonepattern and treatNoneas "no extra unstackable keys":Two-line change. Behavior is identical for every call site (the default is still effectively an empty iterable). The function is exposed at module level, so callers passing an explicit list continue to work unchanged.
Verification
unstackable_keys=None→None or [] == []→ loop is skipped (matches old behavior).unstackable_keys=["foo"]→ loop runs over["foo"](matches old behavior).unstackable_keys=[]→ loop is skipped (matches old behavior).