Skip to content

Fix mutable default argument in build_annotation_segments#92

Open
arpitjain099 wants to merge 1 commit into
dbetchkal:mainfrom
arpitjain099:fix/mutable-default-segments
Open

Fix mutable default argument in build_annotation_segments#92
arpitjain099 wants to merge 1 commit into
dbetchkal:mainfrom
arpitjain099:fix/mutable-default-segments

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

The audible_ranges parameter in build_annotation_segments() defaults to a mutable list []. In Python, mutable defaults are shared across all calls to the function, so if any caller ever modified it in place the default would be permanently changed for subsequent calls.

The fix replaces the default with None and initializes a fresh list inside the function body. This is a standard Python pattern for avoiding the mutable default gotcha.

Also adds a few tests:

  • Verifies the default isn't shared across consecutive calls
  • Covers collapse_audible_ranges with empty input and adjacent ranges (where end == start of the next, which the counter-based algorithm correctly merges)

The audible_ranges parameter defaulted to a mutable list ([]),
which is shared across all calls. Replace with None and
initialize inside the function body.

Also adds tests for the default-isolation invariant, empty
input to collapse_audible_ranges, and adjacent-range merging.

Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
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