Skip to content

Commit 1c3abd9

Browse files
committed
Add __mul__ and __rmul__ overrides to PaginationList
Same C-level truncation issue as __add__ — list.__mul__ reads ob_item directly and silently only repeats already-fetched pages. Each override calls _fetch_all() first, then delegates to list.__mul__. Added 4 tests (single-page and multi-page for each).
1 parent 3883280 commit 1c3abd9

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

pyiceberg/typedef.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,13 @@ def __radd__(self, other: list[T]) -> list[T]:
345345
"""Return other + self as a plain list, fetching all pages first."""
346346
self._fetch_all()
347347
return list.__add__(other, self)
348+
349+
def __mul__(self, n: SupportsIndex) -> list[T]:
350+
"""Return self * n as a plain list, fetching all pages first."""
351+
self._fetch_all()
352+
return list.__mul__(self, n)
353+
354+
def __rmul__(self, n: SupportsIndex) -> list[T]:
355+
"""Return n * self as a plain list, fetching all pages first."""
356+
self._fetch_all()
357+
return list.__mul__(self, n)

tests/utils/test_pagination.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ def test_single_page_radd() -> None:
111111
assert [1] + pl == [1, 2, 3]
112112

113113

114+
def test_single_page_mul() -> None:
115+
pl, _ = _simple_pagination_list([[1, 2]])
116+
assert pl * 2 == [1, 2, 1, 2]
117+
118+
119+
def test_single_page_rmul() -> None:
120+
pl, _ = _simple_pagination_list([[1, 2]])
121+
assert 2 * pl == [1, 2, 1, 2]
122+
123+
114124
# ---------------------------------------------------------------------------
115125
# Multi-page: lazily fetches subsequent pages
116126
# ---------------------------------------------------------------------------
@@ -250,6 +260,16 @@ def test_multi_page_radd_fetches_all() -> None:
250260
assert [0] + pl == [0] + expected
251261

252262

263+
def test_multi_page_mul_fetches_all() -> None:
264+
pl, expected = _simple_pagination_list([[1, 2], [3, 4]])
265+
assert pl * 2 == expected * 2
266+
267+
268+
def test_multi_page_rmul_fetches_all() -> None:
269+
pl, expected = _simple_pagination_list([[1, 2], [3, 4]])
270+
assert 2 * pl == 2 * expected
271+
272+
253273
# ---------------------------------------------------------------------------
254274
# Performance: len() should not eagerly fetch all pages for a single-page list
255275
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)