Skip to content

Make BoxList + and * return a BoxList - #359

Merged
cdgriffith merged 2 commits into
cdgriffith:developfrom
rahul05ranjan:boxlist-operators
Nov 13, 2026
Merged

cdgriffith merged 2 commits into
cdgriffith:developfrom
rahul05ranjan:boxlist-operators

Conversation

@rahul05ranjan

Copy link
Copy Markdown
Contributor

Description

Fixes #358.

BoxList's out-of-place + and * operators fell through to plain list, dropping the class, the box options and — for + — the conversion of appended items:

bl = BoxList([{"a": 1}])
result = bl + [{"b": 2}]
# type(result) -> list; type(result[1]) -> dict (never converted)

What changes

__add__ and __mul__ now build the result through BoxList.__init__, so:

  • the result is a BoxList carrying the left operand's box options;
  • items appended by + are converted exactly like append/extend convert them;
  • a frozen operand yields a frozen result, matching Box.__add__'s frozen handling (the freeze happens after __init__ has stored the items);
  • + with a non-list and * with a non-int raise BoxTypeError.

The in-place variants (+=, *=) were already correct and are unchanged.

Validation Performed

  • 6 new tests in TestBoxListOperators (test/test_box_list.py): all fail on master (plain-list results), all pass with this change
  • Full suite: 681 passed + 16 failed with this change vs 675 + 16 on master — the delta is the 6 new tests; the 16 are pre-existing toml/toml-w-missing and ruamel-version artifacts on this host, unrelated to this change (identical failure list both runs)

This change was made with the help of an AI agent, which located the missing operators and wrote the patch and tests under my direction.

The out-of-place operators fell through to plain list, dropping the
class, the box options and the conversion of appended items:

    BoxList([{'a': 1}]) + [{'b': 2}]  -> plain list, second item a raw dict
    BoxList([{'a': 1}]) * 2          -> plain list

__add__ and __mul__ now return a BoxList with the same box options;
appended items are converted the same way append/extend convert them,
and a frozen operand produces a frozen result. The in-place variants
were already correct.

Fixes cdgriffith#358

Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
cdgriffith added a commit that referenced this pull request Nov 11, 2026
# Conflicts:
#	test/test_box_list.py
@cdgriffith
cdgriffith changed the base branch from master to develop November 13, 2026 17:12
# Conflicts:
#	test/test_box_list.py
@cdgriffith
cdgriffith merged commit 01efaba into cdgriffith:develop Nov 13, 2026
34 of 36 checks passed
@rahul05ranjan

Copy link
Copy Markdown
Contributor Author

Thanks for the merge on #359 ("Make BoxList + and * return a BoxList").

I'm also exploring my next role right now (Full Stack (PHP, NodeJs, Python) / Data Science / Applied AI / Devtools, based in India) — if you or your network is hiring, I'd love an intro:
LinkedIn: https://www.linkedin.com/in/rahulswt7/ · GitHub: https://github.com/rahul05ranjan

@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.

BoxList and operators return plain lists with unconverted items

2 participants