[Python-checkins] gh-94808: Coverage: Check picklablability of calliter (#95923)

orsenthil webhook-mailer at python.org
Mon Oct 3 16:50:38 EDT 2022


https://github.com/python/cpython/commit/cfbc7dd91059cb663c7fe13c661665943495ed7f
commit: cfbc7dd91059cb663c7fe13c661665943495ed7f
branch: main
author: Michael Droettboom <mdboom at gmail.com>
committer: orsenthil <senthilx at amazon.com>
date: 2022-10-03T13:50:30-07:00
summary:

gh-94808: Coverage: Check picklablability of calliter (#95923)

files:
M Lib/test/test_iter.py

diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
index 554f602f6252..acbdcb5f3020 100644
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -81,6 +81,16 @@ class BadIterableClass:
     def __iter__(self):
         raise ZeroDivisionError
 
+class CallableIterClass:
+    def __init__(self):
+        self.i = 0
+    def __call__(self):
+        i = self.i
+        self.i = i + 1
+        if i > 100:
+            raise IndexError # Emergency stop
+        return i
+
 # Main test suite
 
 class TestCase(unittest.TestCase):
@@ -237,16 +247,7 @@ def __iter__(self):
 
     # Test two-argument iter() with callable instance
     def test_iter_callable(self):
-        class C:
-            def __init__(self):
-                self.i = 0
-            def __call__(self):
-                i = self.i
-                self.i = i + 1
-                if i > 100:
-                    raise IndexError # Emergency stop
-                return i
-        self.check_iterator(iter(C(), 10), list(range(10)), pickle=False)
+        self.check_iterator(iter(CallableIterClass(), 10), list(range(10)), pickle=True)
 
     # Test two-argument iter() with function
     def test_iter_function(self):



More information about the Python-checkins mailing list