Skip to content

bpo-29942: Fix the use of recursion in itertools.chain.from_iterable. #889

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 5 commits into from
Mar 30, 2017

Conversation

Yhg1s
Copy link
Member

@Yhg1s Yhg1s commented Mar 29, 2017

Fix the use of recursion in itertools.chain.from_iterable. Using recursion is unnecessary, and can easily cause stack overflows, especially when building in low optimization modes or with Py_DEBUG enabled.

…rsion

is unnecessary, and can easily cause stack overflows, especially when
building in low optimization modes or with Py_DEBUG enabled.
@mention-bot
Copy link

@Yhg1s, thanks for your PR! By analyzing the history of the files in this pull request, we identified @rhettinger, @kristjanvalur and @serhiy-storchaka to be potential reviewers.

@serhiy-storchaka
Copy link
Member

Please open an issue on the bug tracker, add an entry in Misc/NEWS at the start of the "Library" section (don't forget to add "Patch by ."), and add your name in Misc/ACK.

@serhiy-storchaka
Copy link
Member

The patch itself LGTM.

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error needs backport to 2.7 labels Mar 29, 2017
@Yhg1s
Copy link
Member Author

Yhg1s commented Mar 29, 2017

bugs.python.org issue is http://bugs.python.org/issue29942. Misc/NEWS entry added. I'm already in Misc/ACKS, and considering I've been a core dev for many years I don't think I need separate credits for the patch.

@serhiy-storchaka
Copy link
Member

Oh, sorry. Your GitHab name was not known to me.

@serhiy-storchaka serhiy-storchaka changed the title Fix the use of recursion in itertools.chain.from_iterable. bpo-29942: Fix the use of recursion in itertools.chain.from_iterable. Mar 29, 2017
# number this would probably only fail in Py_DEBUG mode.
it = chain.from_iterable(() for unused in range(10000000))
with self.assertRaises(StopIteration):
next(it)
Copy link
Member

Choose a reason for hiding this comment

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

Two-space indentation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@@ -1976,6 +1976,14 @@ def gen2(x):
self.assertRaises(AssertionError, list, cycle(gen1()))
self.assertEqual(hist, [0,1])

def test_deep_recursion(self):
Copy link
Member

Choose a reason for hiding this comment

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

Now this is not a recursion. The recursion from user side is chain.from_iterable(chain.from_iterable(...)). Maybe use other name for the test?

Copy link
Member Author

Choose a reason for hiding this comment

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

Name adjusted.

@Yhg1s Yhg1s merged commit 5466d4a into python:master Mar 30, 2017
@Yhg1s Yhg1s deleted the itertools-recursion branch March 30, 2017 16:59
Yhg1s added a commit to Yhg1s/cpython that referenced this pull request Mar 30, 2017
…python#889)

Fix the use of recursion in itertools.chain.from_iterable. Using recursion
is unnecessary, and can easily cause stack overflows, especially when
building in low optimization modes or with Py_DEBUG enabled.
(cherry picked from commit 5466d4a)
Yhg1s added a commit to Yhg1s/cpython that referenced this pull request Mar 30, 2017
…python#889)

Fix the use of recursion in itertools.chain.from_iterable. Using recursion
is unnecessary, and can easily cause stack overflows, especially when
building in low optimization modes or with Py_DEBUG enabled.
(cherry picked from commit 5466d4a)
Yhg1s added a commit to Yhg1s/cpython that referenced this pull request Mar 30, 2017
…python#889)

Fix the use of recursion in itertools.chain.from_iterable. Using recursion
is unnecessary, and can easily cause stack overflows, especially when
building in low optimization modes or with Py_DEBUG enabled.
(cherry picked from commit 5466d4a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants