Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a1fdcf

Browse files
committed
#7782: add a test for test_iter.
1 parent 3813c9e commit 4a1fdcf

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_iter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,21 @@ def __next__(self):
876876
except TypeError:
877877
pass
878878

879+
def test_extending_list_with_iterator_does_not_segfault(self):
880+
# The code to extend a list with an iterator has a fair
881+
# amount of nontrivial logic in terms of guessing how
882+
# much memory to allocate in advance, "stealing" refs,
883+
# and then shrinking at the end. This is a basic smoke
884+
# test for that scenario.
885+
def gen():
886+
for i in range(500):
887+
yield i
888+
lst = [0] * 500
889+
for i in range(240):
890+
lst.pop(0)
891+
lst.extend(gen())
892+
self.assertEqual(len(lst), 760)
893+
879894

880895
def test_main():
881896
run_unittest(TestCase)

0 commit comments

Comments
 (0)