Skip to content

Fix BarrelList concatenation losing stored items - #540

Closed
theman6660 wants to merge 1 commit into
mahmoud:masterfrom
theman6660:codex/fix-barrellist-concatenation
Closed

theman6660 wants to merge 1 commit into
mahmoud:masterfrom
theman6660:codex/fix-barrellist-concatenation

Conversation

@theman6660

Copy link
Copy Markdown

The change

BarrelList inherits list.__add__, which reads the unused base-list storage instead of its partitioned contents:

from boltons.listutils import BarrelList

BarrelList([1, 2]) + [3]  # currently [3], expected [1, 2, 3]
[0] + BarrelList([1, 2])  # currently [0], expected [0, 1, 2]
BarrelList([1, 2]) + BarrelList([3, 4])  # currently [], expected [1, 2, 3, 4]

Implement non-mutating forward and reflected concatenation using the actual contents. Preserve the existing plain-list result type, shallow element references, unchanged operands, list-only inputs, and reflected operator dispatch for unsupported operand types. Ordinary list subclasses retain their underlying-storage concatenation semantics.

The regression matrix covers both operand directions and two BarrelLists, single/multiple partitions including empty partitions, empty/nonempty inputs, duplicates, unhashable elements, independent result storage, self-concatenation, non-list rejection, and reflected dispatch.

Validation on Windows / Python 3.12.10 in a virtual environment:

  • Unchanged implementation: 678 tests/doctests and 12 subtests passed.
  • New cases before the fix: 28 failed and 17 passing controls.
  • Fixed source: 723 tests/doctests and 12 subtests passed.
  • Built and installed wheel, with the imported package path verified outside the checkout: the same 723 tests/doctests and 12 subtests passed.
  • git diff --check: passed.
  • An optional Ruff check reports the same eight pre-existing diagnostics on the original and patched files; no unrelated cleanup is included.

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

The backstory

Earlier contribution: #519, which contains my contribution background. This was found during Codex-assisted checks of the documented list interface while continuing small, verifiable open-source contributions; it was not observed in production. The advertised list-compatible API prompted a comparison with ordinary concatenation, exposing silent loss of the partitioned contents.

AI assistance

  • Harness/tooling: OpenAI Codex desktop. Codex inspected the source and contribution rules, searched existing issues and PRs, reproduced the defect, implemented the correction and tests, and ran validation under the contributor's authorization.
  • Model(s): GPT-6-based Codex; the exact serving-model identifier is not exposed in this session.
  • Original prompt, verbatim: “给我继续做项目去” (“Continue working on projects for me”), in the context of continuing the contributor's GitHub PR work.

@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