Skip to content

Stop BoxList.extend from revisiting its own appended values - #332

Open
x0Lazarus wants to merge 1 commit into
cdgriffith:developfrom
x0Lazarus:fix/extend-boxlist-with-self
Open

x0Lazarus wants to merge 1 commit into
cdgriffith:developfrom
x0Lazarus:fix/extend-boxlist-with-self

Conversation

@x0Lazarus

Copy link
Copy Markdown

Calling values.extend(values) on a nonempty BoxList keeps appending because the loop also visits the values it has just added. A regular Python list appends its original contents once and returns.

Take a snapshot only when the input is the destination list itself, then use the existing append path. This keeps container conversion and list options in place. Other iterables remain lazy, including their existing partial-progress behavior if iteration raises an error.

Tests cover empty lists, scalar and nested values, and an iterator that fails after yielding a value. The self-extension tests bound the number of appends so they fail safely before the fix. Three cases fail on the unchanged base. All 164 tests pass with both pure Python and the compiled Cython extension on Windows with Python 3.12; mypy, changed-file formatting, package builds and Twine checks also pass. Other Python versions and operating systems were not run locally.

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