-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Conversation
…rsion is unnecessary, and can easily cause stack overflows, especially when building in low optimization modes or with Py_DEBUG enabled.
@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. |
Please open an issue on the bug tracker, add an entry in |
The patch itself LGTM. |
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. |
Oh, sorry. Your GitHab name was not known to me. |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two-space indentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Lib/test/test_itertools.py
Outdated
@@ -1976,6 +1976,14 @@ def gen2(x): | |||
self.assertRaises(AssertionError, list, cycle(gen1())) | |||
self.assertEqual(hist, [0,1]) | |||
|
|||
def test_deep_recursion(self): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name adjusted.
…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)
…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)
…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)
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 withPy_DEBUG
enabled.