Skip to content

Commit 6289836

Browse files
committed
test(immutable): assert length snapshot behavior
`ImmutableList` does not store a `_length` attribute; length is derived from the immutable `_items` tuple. The previous test passed by trying to assign a nonexistent frozen dataclass field, which did not verify any real length state. Replace it with a behavior-focused assertion: constructing from a mutable list takes a tuple snapshot, so later mutations to the source list do not affect `len()`. No runtime behavior change; the full tox matrix (lint, mypy strict, unit tests on Python 3.10-3.14) passes.
1 parent 3e38669 commit 6289836

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tests/test_immutable_list.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ def test_immutable_items_attribute(self) -> None:
8484
il.__setattr__('_items', 10)
8585

8686
def test_immutable_length(self) -> None:
87-
il = ImmutableList(1, 2, 3, 4, 5)
88-
with self.assertRaises(FrozenInstanceError):
89-
il.__setattr__('_length', 10)
87+
items = [1, 2, 3, 4, 5]
88+
il = ImmutableList[int](items)
89+
90+
items.append(6)
91+
92+
self.assertEqual(len(il), 5)
9093

9194
def test_map_values_from_a_tuple(self) -> None:
9295
values = (1, 2, 3, 4, 5)

0 commit comments

Comments
 (0)