From ba0769f982972d6528c21b3b486b95dfae526f7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Sun, 1 Jan 2023 21:01:35 +0100
Subject: [PATCH] v2.23.0 add contains test to ListWrapperIterator

---
 CHANGELOG.md                          |  3 ++-
 satella/__init__.py                   |  2 +-
 satella/coding/sequences/iterators.py | 15 ++++++++++++---
 tests/test_coding/test_iterators.py   | 14 ++++++++++++++
 4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1bd2d038..aea88aaf 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 df438184..d0c0c476 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 944ab26a..5fabe827 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 16e3b103..56a790f7 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}
 
-- 
GitLab