Skip to content

Fix mutable default list argument in config classes#384

Open
hobostay wants to merge 1 commit into
microsoft:mainfrom
hobostay:fix/mutable-default-args
Open

Fix mutable default list argument in config classes#384
hobostay wants to merge 1 commit into
microsoft:mainfrom
hobostay:fix/mutable-default-args

Conversation

@hobostay

@hobostay hobostay commented May 4, 2026

Copy link
Copy Markdown

Summary

  • Fix mutable default argument encoder_ratios=[8,5,5,4,2,2] in VibeVoiceAcousticTokenizerConfig and VibeVoiceSemanticTokenizerConfig
  • Python evaluates default arguments once at class definition time, so all instances share the same list object
  • Mutating the list on one instance (e.g., via .append(), .sort()) would silently corrupt all other instances
  • Also use list(encoder_ratios) when assigning decoder_ratios to avoid shared references

Details

Affected file: vibevoice/modular/configuration_vibevoice.py (lines 55, 118)

Changed encoder_ratios: Optional[List[int]] = [8,5,5,4,2,2] to encoder_ratios: Optional[List[int]] = None with if encoder_ratios is None: encoder_ratios = [8, 5, 5, 4, 2, 2] inside the method body. This is a well-known Python pitfall.

Test plan

  • Verify configs can still be instantiated without arguments (default values preserved)
  • Verify mutations on one config instance don't affect others

🤖 Generated with Claude Code

Replace mutable default `encoder_ratios=[8,5,5,4,2,2]` with `None`
and initialize inside the method body. Python evaluates default
arguments once at class definition time, so all instances share the
same list object. Mutating it on one instance would silently corrupt
all others.

Also use `list(encoder_ratios)` when assigning `decoder_ratios` from
`encoder_ratios` to avoid shared references between encoder and decoder.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@rickthomasjr rickthomasjr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Approve — fix mutable default list argument

Correctness: Default encoder_ratios: Optional[List[int]] = [8,5,5,4,2,2] is a classic Python mutable default argument bug. All instances of the class would share the same list object, leading to cross-talk between configs.

Fix is standard: Switch to None default and assign in-body. Clean and idiomatic.

Verdict: Approve. Correct fix for a well-known Python gotcha.

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.

2 participants