Skip to content

Commit fe99b64

Browse files
gh-94808: Coverage: Check picklablability of calliter (GH-95923)
(cherry picked from commit cfbc7dd) Co-authored-by: Michael Droettboom <[email protected]>
1 parent 4d4b1e6 commit fe99b64

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Lib/test/test_iter.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ class BadIterableClass:
8181
def __iter__(self):
8282
raise ZeroDivisionError
8383

84+
class CallableIterClass:
85+
def __init__(self):
86+
self.i = 0
87+
def __call__(self):
88+
i = self.i
89+
self.i = i + 1
90+
if i > 100:
91+
raise IndexError # Emergency stop
92+
return i
93+
8494
# Main test suite
8595

8696
class TestCase(unittest.TestCase):
@@ -237,16 +247,7 @@ def __iter__(self):
237247

238248
# Test two-argument iter() with callable instance
239249
def test_iter_callable(self):
240-
class C:
241-
def __init__(self):
242-
self.i = 0
243-
def __call__(self):
244-
i = self.i
245-
self.i = i + 1
246-
if i > 100:
247-
raise IndexError # Emergency stop
248-
return i
249-
self.check_iterator(iter(C(), 10), list(range(10)), pickle=False)
250+
self.check_iterator(iter(CallableIterClass(), 10), list(range(10)), pickle=True)
250251

251252
# Test two-argument iter() with function
252253
def test_iter_function(self):

0 commit comments

Comments
 (0)