Skip to content

Fix BarrelList in-place repetition - #532

Closed
hansu650 wants to merge 1 commit into
mahmoud:masterfrom
hansu650:fix/barrellist-inplace-repeat
Closed

hansu650 wants to merge 1 commit into
mahmoud:masterfrom
hansu650:fix/barrellist-inplace-repeat

Conversation

@hansu650

@hansu650 hansu650 commented Oct 3, 2026

Copy link
Copy Markdown

The change

Fix BarrelList's in-place repetition (*= n). It currently inherits list.__imul__, which operates on the unused base-list storage instead of BarrelList.lists:

from boltons.listutils import BarrelList

values = BarrelList([1, 2])
values *= 2
print(list(values))  # currently [1, 2]; expected [1, 2, 1, 2]
values *= 0
print(list(values))  # currently [1, 2]; expected []

The implementation uses native list repetition on the actual contents, retains the same BarrelList object, then rebalances its storage. It normalizes __index__ before copying multi-barrel contents, preserves shallow element sharing, and delegates invalid-count/overflow behavior to the native list operation. Other list operators are unchanged. This branch is based directly on upstream master and does not depend on #517 or #530.

Tests and validation

Dedicated Conda Python 3.13.15 environment on Windows:

  • 65 new cases covering empty/single/multiple barrels, positive/zero/negative/bool counts, the index protocol, invalid/overflowing counts, object identity, shared element references, and a real 100,000-element balanced list. On unchanged upstream, 31 cases fail and 34 pass; all 65 pass after the fix.
  • Listutils selection: 76 passed.
  • Full source suite, including module doctests: 743 passed, 12 subtests passed.
  • Clean Git-export sdist/wheel build and Twine checks: passed.
  • Isolated installed-wheel suite, with the import path and source hash checked: 743 passed, 12 subtests passed.
  • New method: all 8 statements and 2 branches covered.
  • A local seeded differential check of 4,000 repeated operations against native lists, interleaved with appends/pops, passed.
  • Ruff's default checks on the new test file, focused correctness checks on listutils.py, and pip check: passed. No repository-wide formatting changes were made.

Other Python versions/operating systems and remote CI are not claimed as passing from this local run.

The backstory

Related contribution: #517 (self-extension). This separate inherited-list mutation issue was found during agent-assisted checks of BarrelList's advertised list-compatible behavior, not from a production incident. Reviewing the storage split made it clear why delegating to the inherited method could silently leave the visible sequence unchanged.

AI assistance

  • Harness/tooling: OpenAI Codex desktop; code, tests, validation and this description were prepared with Codex assistance.
  • Model(s): OpenAI Codex; the exact serving-model identifier is not exposed in this session.
  • Original prompt, verbatim: “一样的把前面的处理一下新信息,然后在做一个新的” (check and handle new information on the earlier contributions, then make one new contribution, under the existing contribution requirements).

@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