summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorT. Wouters <thomas@python.org>2017-03-30 19:48:23 (GMT)
committerGitHub <noreply@github.com>2017-03-30 19:48:23 (GMT)
commit599bb181036f724629a515317f0f39520950d51c (patch)
tree3cf9853bf9edd48a8f04b0592e59ecb34f07e26a /Lib/test
parent7b5b1379ac2c1e89ebf90b88b5d32457910e975e (diff)
downloadcpython-599bb181036f724629a515317f0f39520950d51c.zip
cpython-599bb181036f724629a515317f0f39520950d51c.tar.gz
cpython-599bb181036f724629a515317f0f39520950d51c.tar.bz2
bpo-29942: Fix the use of recursion in itertools.chain.from_iterable. (#911)
* bpo-29942: Fix the use of recursion in itertools.chain.from_iterable. 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 5466d4af5fe76ec0a5fbc8a05675287d9e8e9d14)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_itertools.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index ea1f57c..c431f0d 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -1976,6 +1976,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...