Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ reporting, all input is greatly appreciated!

Code contributions:

- fhgffy

- Alexandre Decan (AlexandreDecan)
- dhilipsiva (dhilipsiva)
- MAA (FooBarQuaxx)
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

Unreleased
----------

* Fix BoxList construction from iterable inputs with false or ambiguous truth values.

Version 7.4.1
-------------

Expand Down
3 changes: 2 additions & 1 deletion box/box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def __init__(self, iterable: Iterable | None = None, box_class: type[box.Box] =
self.box_options = box_options
self.box_options["box_class"] = box_class
self.box_org_ref = iterable
if iterable:
# 2026-10-10: Iteration does not require a truth value.
if iterable is not None:
for x in iterable:
self.append(x)
self.box_org_ref = None
Expand Down
16 changes: 16 additions & 0 deletions test/test_box_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def test_box_list(self):
assert isinstance(new_list[1], BoxList)
assert not isinstance(new_list.to_list(), BoxList)

@pytest.mark.parametrize("falsey", [False, True])
def test_box_list_does_not_require_iterable_truth_value(self, falsey):
# 2026-10-10: Iterable inputs can be falsey or have no boolean value.
class Rows:
def __iter__(self):
return iter([{"value": 1}])

def __bool__(self):
if falsey:
return False
raise ValueError("ambiguous truth value")

result = BoxList(Rows())
assert len(result) == 1
assert result[0].value == 1

def test_frozen_list(self):
bl = BoxList([5, 4, 3], frozen_box=True)
with pytest.raises(BoxError):
Expand Down