Page MenuHomeSoftware Heritage

D4087.id14465.diff
No OneTemporary

D4087.id14465.diff

diff --git a/swh/core/collections.py b/swh/core/collections.py
--- a/swh/core/collections.py
+++ b/swh/core/collections.py
@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information
import bisect
-import collections
import itertools
from typing import Any, Callable, Generic, Iterator, List, Optional, Tuple, TypeVar
@@ -12,7 +11,7 @@
SortedListKey = TypeVar("SortedListKey")
-class SortedList(collections.UserList, Generic[SortedListKey, SortedListItem]):
+class SortedList(Generic[SortedListKey, SortedListItem]):
data: List[Tuple[SortedListKey, SortedListItem]]
# https://github.com/python/mypy/issues/708
@@ -29,7 +28,7 @@
return item
assert key is not None # for mypy
- super().__init__(sorted((key(x), x) for x in data or []))
+ self.data = sorted((key(x), x) for x in data or [])
self.key: Callable[[SortedListItem], SortedListKey] = key
diff --git a/swh/core/tests/test_collections.py b/swh/core/tests/test_collections.py
--- a/swh/core/tests/test_collections.py
+++ b/swh/core/tests/test_collections.py
@@ -69,3 +69,18 @@
for split in items:
expected = reversed(sorted(item for item in items if item < split))
assert list(list_.iter_after(-split)) == list(expected), f"split: {split}"
+
+
+@parametrize
+def test_contains(items):
+ list_ = SortedList()
+ for i in range(len(items)):
+ for item in items[0:i]:
+ assert item in list_
+ for item in items[i:]:
+ assert item not in list_
+
+ list_.add(items[i])
+
+ for item in items:
+ assert item in list_

File Metadata

Mime Type
text/plain
Expires
Dec 21 2024, 12:25 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218215

Event Timeline