commit: 40ba0abd95d2c7004109469ce2aaeb270570bfee
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sun Nov 30 21:43:24 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sun Nov 30 22:34:56 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=40ba0abd
refactor(sequences): drop unused ChainedLists
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/sequences.py | 87 +----------------------------------------------
tests/test_sequences.py | 50 ---------------------------
2 files changed, 1 insertion(+), 136 deletions(-)
diff --git a/src/snakeoil/sequences.py b/src/snakeoil/sequences.py
index b075bfb..ba64d84 100644
--- a/src/snakeoil/sequences.py
+++ b/src/snakeoil/sequences.py
@@ -6,12 +6,11 @@ __all__ = (
"iter_stable_unique",
"iflatten_instance",
"iflatten_func",
- "ChainedLists",
"predicate_split",
"split_negations",
+ "split_elements",
)
-import functools
from typing import Any, Callable, Iterable, Type
from .iterables import expandable_chain
@@ -148,90 +147,6 @@ def iflatten_func(l: Iterable, skip_func: Callable[[Any],
bool]) -> Iterable:
pass
-class ChainedLists:
- """Given a set of sequences, this will act as a proxy to them without
- collapsing them into a single list.
-
- This is primarily useful when you're dealing in large sets (or custom
- sequence objects), and do not want to collapse them into one sequence- but
- you still want to be able to access them as if they were one sequence.
-
- Note that while you can add more lists onto this, you cannot directly
- change the underlying lists through this class.
-
- >>> from snakeoil.sequences import ChainedLists
- >>> l1, l2 = [0, 1, 2, 3], [4,5,6]
- >>> cl = ChainedLists(l1, l2)
- >>> print(cl[3])
- 3
- >>> print(cl[4])
- 4
- >>> print(cl[0])
- 0
- >>> assert 4 in cl
- >>> print(len(cl))
- 7
- >>> cl[0] = 9
- Traceback (most recent call last):
- ...
- TypeError: not mutable
- """
-
- __slots__ = ("_lists", "__weakref__")
-
- def __init__(self, *lists):
- """
- all args must be sequences
- """
- # ensure they're iterable
- for x in lists:
- iter(x)
-
- if isinstance(lists, tuple):
- lists = list(lists)
- self._lists = lists
-
- def __len__(self):
- return sum(len(l) for l in self._lists)
-
- def __getitem__(self, idx):
- if idx < 0:
- idx += len(self)
- if idx < 0:
- raise IndexError
- for l in self._lists:
- l2 = len(l)
- if idx < l2:
- return l[idx]
- idx -= l2
- raise IndexError
-
- def __setitem__(self, idx, val):
- raise TypeError("not mutable")
-
- def __delitem__(self, idx):
- raise TypeError("not mutable")
-
- def __iter__(self):
- for l in self._lists:
- for x in l:
- yield x
-
- def __contains__(self, obj):
- return obj in iter(self)
-
- def __str__(self):
- return "[ %s ]" % ", ".join(str(l) for l in self._lists)
-
- @functools.wraps(list.append)
- def append(self, item):
- self._lists.append(item)
-
- @functools.wraps(list.extend)
- def extend(self, items):
- self._lists.extend(items)
-
-
def predicate_split(func, stream, key=None):
"""
Given a stream and a function, split the stream into two sequences based on
diff --git a/tests/test_sequences.py b/tests/test_sequences.py
index b558647..ab4a9fe 100644
--- a/tests/test_sequences.py
+++ b/tests/test_sequences.py
@@ -58,56 +58,6 @@ class TestStableUnique:
assert sorted(sequences.unstable_unique(self._generator())) ==
sorted(range(6))
-class TestChainedLists:
- @staticmethod
- def gen_cl():
- return sequences.ChainedLists(
- list(range(3)), list(range(3, 6)), list(range(6, 100))
- )
-
- def test_contains(self):
- cl = self.gen_cl()
- for x in (1, 2, 4, 99):
- assert x in cl
-
- def test_iter(self):
- assert list(self.gen_cl()) == list(range(100))
-
- def test_len(self):
- assert len(self.gen_cl()) == 100
-
- def test_str(self):
- l = sequences.ChainedLists(list(range(3)), list(range(3, 5)))
- assert str(l) == "[ [0, 1, 2], [3, 4] ]"
-
- def test_getitem(self):
- cl = self.gen_cl()
- for x in (1, 2, 4, 98, -1, -99, 0):
- # "Statement seems to have no effect"
- # pylint: disable=W0104
- cl[x]
- with pytest.raises(IndexError):
- cl.__getitem__(100)
- with pytest.raises(IndexError):
- cl.__getitem__(-101)
-
- def test_mutable(self):
- with pytest.raises(TypeError):
- self.gen_cl().__delitem__(1)
- with pytest.raises(TypeError):
- self.gen_cl().__setitem__(1, 2)
-
- def test_append(self):
- cl = self.gen_cl()
- cl.append(list(range(10)))
- assert len(cl) == 110
-
- def test_extend(self):
- cl = self.gen_cl()
- cl.extend(list(range(10)) for i in range(5))
- assert len(cl) == 150
-
-
class Test_iflatten_instance:
func = staticmethod(sequences.iflatten_instance)