Skip to content

Fix unbounded BarrelList self-extension - #517

Closed
hansu650 wants to merge 1 commit into
mahmoud:masterfrom
hansu650:fix/barrellist-self-extend
Closed

hansu650 wants to merge 1 commit into
mahmoud:masterfrom
hansu650:fix/barrellist-self-extend

Conversation

@hansu650

Copy link
Copy Markdown

The change

Make BarrelList.extend(self) terminate with the same contents as a built-in list extended with itself. The current implementation passes the BarrelList's live iterator to its last underlying list; that iterator then consumes newly appended values and continues growing.

Snapshot only when the iterable is the receiver itself. Other iterables retain the existing streaming behavior, including partial updates when an iterator raises. This does not change extend(iter(value)), for which a built-in list also has a live-iterator hazard.

The regression tests cap iteration at the original length so a failure cannot hang the test runner or exhaust its memory. They cover empty lists, single/multiple barrels, empty internal/tail barrels, object identity, other iterable types, and a failing iterator.

Validation on Windows / CPython 3.13.15:

  • Before the fix: 4 of 11 new regression/control cases fail.
  • Full source suite and module doctests: 689 passed, 12 subtests passed.
  • Full installed-wheel suite and module doctests, using isolated Python imports: 689 passed, 12 subtests passed.
  • The changed extend method has 100% statement and branch coverage.
  • An additional local check without the iterator guard passed 780 repeated self-extensions across varying list sizes and barrel layouts. A balanced 100,000-element list doubled correctly and remained usable for insert/pop.
  • Clean-export sdist/wheel builds, Twine checks, dependency consistency and git diff --check passed.

Other Python versions and operating systems have not been run locally.

The backstory

This follows the built-in-compatible data-structure investigation in #516. The submitting account asked Codex to check the existing PRs and prepare another contribution if none had merged. The self-extension problem was found through source inspection and bounded regression tests, not in a production application.

AI assistance

  • Harness/tooling: OpenAI Codex, acting under the submitting account's authorization.
  • Model(s): GPT-5-based agent; the exact model variant is not exposed in this session.
  • Original prompt, verbatim: “怎么样有没有pr合并,没有的话再去做一个”
  • Translation: “How is it going—have any PRs merged? If not, go make another one.”

Codex inspected the contribution guidance and previous PRs, wrote and ran the tests, implemented the fix, and prepared this PR. No independent human review or production usage is claimed.

Snapshot self-extension before appending, while preserving streaming behavior for other iterables. Add bounded regression tests and compatibility controls.

Assisted-by: OpenAI Codex
@mahmoud

mahmoud commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Folded into #609 (see the PR description for credit). Thanks for the report and the repro.

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