Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
Yhg1s merged 5 commits into
python:masterpython/cpython:masterfrom
Yhg1s:itertools-recursionYhg1s/cpython:itertools-recursionCopy head branch name to clipboard
Mar 30, 2017
Merged

bpo-29942: Fix the use of recursion in itertools.chain.from_iterable.#889
Yhg1s merged 5 commits into
python:masterpython/cpython:masterfrom
Yhg1s:itertools-recursionYhg1s/cpython:itertools-recursionCopy head branch name to clipboard

Conversation

@Yhg1s

@Yhg1s Yhg1s commented Mar 29, 2017

Copy link
Copy Markdown
Member

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
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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

Yhg1s commented Mar 29, 2017

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Comment thread Lib/test/test_itertools.py Outdated
# 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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread Lib/test/test_itertools.py Outdated
self.assertRaises(AssertionError, list, cycle(gen1()))
self.assertEqual(hist, [0,1])

def test_deep_recursion(self):

Copy link
Copy Markdown
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
Copy Markdown
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.