Issue #14010: Fix a crash when iterating or deleting deeply nested filters

(builting and in itertools module, i.e. map(), itertools.chain(), etc).
This commit is contained in:
Serhiy Storchaka 2013-04-06 21:14:43 +03:00
parent e16f4dc80a
commit e8f706eda7
6 changed files with 225 additions and 15 deletions

View file

@ -1565,8 +1565,40 @@ class TestSorted(unittest.TestCase):
data = 'The quick Brown fox Jumped over The lazy Dog'.split()
self.assertRaises(TypeError, sorted, data, None, lambda x,y: 0)
class TestRecursionLimit(unittest.TestCase):
# Issue #14010
recursionlimit = sys.getrecursionlimit()
def test_filter(self):
it = (0, 1)
for _ in range(self.recursionlimit):
it = filter(bool, it)
with self.assertRaises(RuntimeError):
for _ in it:
pass
del it
def test_map(self):
it = (0, 1)
for _ in range(self.recursionlimit):
it = map(int, it)
with self.assertRaises(RuntimeError):
for _ in it:
pass
del it
def test_zip(self):
it = (0, 1)
for _ in range(self.recursionlimit):
it = zip(it)
with self.assertRaises(RuntimeError):
for _ in it:
pass
del it
def test_main(verbose=None):
test_classes = (BuiltinTest, TestSorted)
test_classes = (BuiltinTest, TestSorted, TestRecursionLimit)
run_unittest(*test_classes)