Kaydet (Commit) 1b5f9c96 authored tarafından Naris R's avatar Naris R Kaydeden (comit) Raymond Hettinger

bpo-34427: Fix infinite loop when calling MutableSequence.extend() on self (GH-8813)

üst e6dac007
......@@ -986,6 +986,8 @@ class MutableSequence(Sequence):
def extend(self, values):
'S.extend(iterable) -- extend sequence by appending elements from the iterable'
if values is self:
values = list(values)
for v in values:
self.append(v)
......
......@@ -1721,6 +1721,18 @@ class TestCollectionABCs(ABCTestCase):
mss.clear()
self.assertEqual(len(mss), 0)
# issue 34427
# extending self should not cause infinite loop
items = 'ABCD'
mss2 = MutableSequenceSubclass()
mss2.extend(items + items)
mss.clear()
mss.extend(items)
mss.extend(mss)
self.assertEqual(len(mss), len(mss2))
self.assertEqual(list(mss), list(mss2))
################################################################################
### Counter
################################################################################
......
Fix infinite loop in ``a.extend(a)`` for ``MutableSequence`` subclasses.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment