mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-29942: Fix the use of recursion in itertools.chain.from_iterable. (#912)
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 5466d4af5f
)
This commit is contained in:
parent
8b8bde44f3
commit
9273dfe180
3 changed files with 39 additions and 24 deletions
|
@ -1943,6 +1943,14 @@ class RegressionTests(unittest.TestCase):
|
|||
self.assertRaises(AssertionError, list, cycle(gen1()))
|
||||
self.assertEqual(hist, [0,1])
|
||||
|
||||
def test_long_chain_of_empty_iterables(self):
|
||||
# Make sure itertools.chain doesn't run into recursion limits when
|
||||
# dealing with long chains of empty iterables. Even with a high
|
||||
# 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)
|
||||
|
||||
class SubclassWithKwargsTest(unittest.TestCase):
|
||||
def test_keywords_in_subclass(self):
|
||||
# count is not subclassable...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue