Fix bug 1604. deque.__init__() did not clear existing contents like list.__init__. Not a backport candidate.

This commit is contained in:
Raymond Hettinger 2007-12-13 00:08:37 +00:00
parent 842c178442
commit adf9ffdfbe
3 changed files with 9 additions and 4 deletions

View File

@ -29,8 +29,8 @@ class MutateCmp:
class TestBasic(unittest.TestCase): class TestBasic(unittest.TestCase):
def test_basics(self): def test_basics(self):
d = deque(xrange(100)) d = deque(xrange(-5125, -5000))
d.__init__(xrange(100, 200)) d.__init__(xrange(200))
for i in xrange(200, 400): for i in xrange(200, 400):
d.append(i) d.append(i)
for i in reversed(xrange(-200, 0)): for i in reversed(xrange(-200, 0)):
@ -451,8 +451,8 @@ class DequeWithBadIter(deque):
class TestSubclass(unittest.TestCase): class TestSubclass(unittest.TestCase):
def test_basics(self): def test_basics(self):
d = Deque(xrange(100)) d = Deque(xrange(25))
d.__init__(xrange(100, 200)) d.__init__(xrange(200))
for i in xrange(200, 400): for i in xrange(200, 400):
d.append(i) d.append(i)
for i in reversed(xrange(-200, 0)): for i in reversed(xrange(-200, 0)):

View File

@ -881,6 +881,10 @@ Library
Extension Modules Extension Modules
----------------- -----------------
- Bug #1604: collections.deque.__init__(iterable) now clears any prior contents
before adding elements from the iterable. This fix brings the behavior into
line with that for list.__init__().
- Added wide char functions to msvcrt module: getwch, getwche, putwch and - Added wide char functions to msvcrt module: getwch, getwche, putwch and
ungetwch. The functions accept or return unicode. ungetwch. The functions accept or return unicode.

View File

@ -843,6 +843,7 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
} }
} }
deque->maxlen = maxlen; deque->maxlen = maxlen;
deque_clear(deque);
if (iterable != NULL) { if (iterable != NULL) {
PyObject *rv = deque_extend(deque, iterable); PyObject *rv = deque_extend(deque, iterable);
if (rv == NULL) if (rv == NULL)