bpo-29942: Fix the use of recursion in itertools.chain.from_iterable. by Yhg1s · Pull Request #889 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation9 Commits5 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

Yhg1s

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.

@Yhg1s

…rsion

is unnecessary, and can easily cause stack overflows, especially when building in low optimization modes or with Py_DEBUG enabled.

@mention-bot

@serhiy-storchaka

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

@Yhg1s

@Yhg1s

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

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

@serhiy-storchaka serhiy-storchaka changed the titleFix the use of recursion in itertools.chain.from_iterable. bpo-29942: Fix the use of recursion in itertools.chain.from_iterable.

Mar 29, 2017

serhiy-storchaka

# 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)

Choose a reason for hiding this comment

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

Two-space indentation?

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):

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?

Choose a reason for hiding this comment

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

Name adjusted.

@Yhg1s

@Yhg1s

serhiy-storchaka

rhettinger

@Yhg1s

@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

@Yhg1s

…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

@Yhg1s

…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

@Yhg1s

…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)

Labels

type-bug

An unexpected behavior, bug, or error