Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Lib/test/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down