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_