Skip to content

Normalize BoxList in-place repetition counts before comment updates - #361

Merged
cdgriffith merged 5 commits into
cdgriffith:developfrom
anishpentyala:fix/normalize-imul-index-count
Nov 13, 2026
Merged

cdgriffith merged 5 commits into
cdgriffith:developfrom
anishpentyala:fix/normalize-imul-index-count

Conversation

@anishpentyala

Copy link
Copy Markdown
Contributor

Problem

BoxList.__imul__ lets the underlying list consume an index-protocol object, then passes the original object to comment repetition. With item comments and a positive count this raises TypeError after the list has already changed, leaving repeated comments missing. This is on current develop, after the insert/pop/delete fix for #354.

from box import BoxList

class Twice:
    def __index__(self):
        return 2

values = BoxList(["a", "b"])
values.set_comment(1, "second")
values *= Twice()  # TypeError after values becomes ["a", "b", "a", "b"]

Change

Normalize the count with operator.index once, after the frozen check and before mutation, then reuse the integer for list repetition and comment bookkeeping. This preserves invalid-count and frozen-list refusal behavior. Changelog and contributor entry included per CONTRIBUTING.

Checks

Linux, CPython 3.12.15, pytest 9.2.0:

  • New regression tests against unchanged develop: 2 failed, 8 passed. Both failures are the post-mutation comment-bookkeeping error.
  • Fixed focused tests: 10 passed, covering positive/zero/negative counts, comments on/off, object identity, once-only conversion, invalid conversion and frozen refusal.
  • Same-environment baseline suite: 1,191 passed, 8 skipped.
  • Fixed pure Python and Cython-compiled suites: 1,201 passed, 8 skipped each. The compiled box.box_list extension path was checked.
  • Fresh clone of the submitted branch: 1,201 passed, 8 skipped; its tree matches the reviewed candidate.
  • Ruff check, Ruff format check and git diff --check pass on changed Python files.

No hosted CI result is claimed. This was found by source inspection and local reproduction, not a claimed production incident.

@cdgriffith
cdgriffith merged commit 2da3008 into cdgriffith:develop Nov 13, 2026
cdgriffith added a commit that referenced this pull request Nov 13, 2026
…mment updates

Normalize BoxList in-place repetition counts before comment updates
@cdgriffith cdgriffith mentioned this pull request Nov 13, 2026
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