8000 gh-101892: Fix SystemError when a callable iterator call exhausts the iterator by workingpayload · Pull Request #101896 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-101892: Fix SystemError when a callable iterator call exhausts the iterator #101896

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

Merged
merged 19 commits into from
Mar 4, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Address the review
  • Loading branch information
arhadthedev committed Mar 4, 2023
commit 1ee22939750381386bc414d187f5011635700290
19 changes: 9 additions & 10 deletions Lib/test/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ def __len__(self):
def __getitem__(self, i):
raise StopIteration


def exhaust(iterator):
"""Exhaust an iterator without raising StopIteration."""
list(iterator)


# Main test suite

class TestCase(unittest.TestCase):
Expand Down Expand Up @@ -354,15 +348,20 @@ def spam(state=[0]):
return i
self.check_iterator(iter(spam, 20), list(range(10)), pickle=False)

# Test two-argument iter() with function that exhausts its
# associated iterator but forgets to either return a sentinel value
# or raise `StopIteration`.
def test_iter_function_concealing_reentrant_exhaustion(self):
# gh-101892: Test two-argument iter() with a function that
# exhausts its associated iterator but forgets to either return
# a sentinel value or raise StopIteration.
HAS_MORE = 1
NO_MORE = 2

def exhaust(iterator):
"""Exhaust an iterator without raising StopIteration."""
list(iterator)

def spam():
# Touching the iterator with exhaust() below will call
# spam() once again
# spam() once again so protect against recursion.
if spam.is_recursive_call:
return NO_MORE
spam.is_recursive_call = True
Expand Down
0