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
8000

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
Next Next commit
Add a test
  • Loading branch information
arhadthedev committed Feb 14, 2023
commit 0c631e3413b0203cfb2335fdeec2363f3e8a31c4
16 changes: 16 additions & 0 deletions Lib/test/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,22 @@ def spam(state=[0]):
return i
self.check_iterator(iter(spam, 20), list(range(10)), pickle=False)

# Test two-argument iter() with function that empties its associated
# iterator with list() (or anything else but next()) then returns
# a non-sentinel value.
def test_iter_function_concealing_reentrant_exhaustion(self):
HAS_MORE = 1
NO_MORE = 2
def spam():
if not spam.is_reentrant:
spam.is_reentrant = True
list(spam.iterator)
return HAS_MORE
return NO_MORE
spam.is_reentrant = False
spam.iterator = iter(spam, NO_MORE)
next(spam.iterator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the expected behaviour here? StopIteration?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for noticing the oversight! Fixed.


# Test exception propagation through function iterator
def test_exception_function(self):
def spam(state=[0]):
Expand Down
0