diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd2d03835bd12590bb6093360cefd009d909ddf..aea88aafedccc33cbfefd739b6813409e5706782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,4 +2,5 @@ * smart_zip to be deprecated in 2.23.0 * removed SIGINT from hang_unti_signal -* updated ListWrapperIterator's signature \ No newline at end of file +* updated ListWrapperIterator's signature +* outfitted ListWrapperIterator with a __contains__ method \ No newline at end of file diff --git a/satella/__init__.py b/satella/__init__.py index df43818420295410dade7384ce40de42666e0702..d0c0c47652493446920615de0d2ac84266a1e3da 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.23.0a1' +__version__ = '2.23.0' diff --git a/satella/coding/sequences/iterators.py b/satella/coding/sequences/iterators.py index 944ab26a4bf01220252666fcddf9f5937625db91..5fabe827551b30411dc7f80b0cf359612346a9ab 100644 --- a/satella/coding/sequences/iterators.py +++ b/satella/coding/sequences/iterators.py @@ -2,7 +2,6 @@ import collections import itertools import typing as tp import warnings -from typing import _T_co from ..decorators import for_argument, wraps from ..recast_exceptions import rethrow_as, silence_excs @@ -515,10 +514,20 @@ class ListWrapperIterator(tp.Iterator[T]): This is additionally a generic class. """ - def __next__(self) -> _T_co: + __slots__ = 'iterator', 'exhausted', 'list' + + def __next__(self) -> T: return self.next() - __slots__ = 'iterator', 'exhausted', 'list' + def __contains__(self, item: T) -> bool: + if item not in self.list and self.exhausted: + return False + for item2 in self: + self.list.append(item2) + if item2 == item: + return True + else: + return False def __init__(self, iterator: Iteratable): self.iterator = iter(iterator) diff --git a/tests/test_coding/test_iterators.py b/tests/test_coding/test_iterators.py index 16e3b103bf4b9956f5090b0b9af73a25fc36bb43..56a790f7ba2da7210faa9ae0d756214847e49a5a 100644 --- a/tests/test_coding/test_iterators.py +++ b/tests/test_coding/test_iterators.py @@ -8,6 +8,20 @@ from satella.coding.sequences import smart_enumerate, ConstruableIterator, walk, class TestIterators(unittest.TestCase): + def test_list_wrapper_iterator_contains(self): + def iterate(): + yield 1 + yield 2 + yield 3 + yield 4 + yield 5 + + lwe = ListWrapperIterator(iterate()) + self.assertTrue(2 in lwe) + self.assertLessEqual(len(lwe.list), 2) + self.assertFalse(6 in lwe) + self.assertEqual(len(lwe.list), 5) + def test_list_wrapper_iterator(self): a = {'count': 0}