This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients mark.dickinson, python-dev, rhettinger, serhiy.storchaka, tim.peters, vstinner
Date 2016-01-27.18:31:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The expected behavior should be "insert normally as if the deque were unbounded and then pop-off the rightmost element to restore the maxlen invariant".

The applied fix does that for non-negative indices but gives the wrong result for negative indicies:

  >>> from collections import deque
  >>> d = deque('abcde', maxlen=5)
  >>> d.insert(-1, 'f')
  >>> list(d)
  ['a', 'b', 'c', 'f', 'd']
  >>> s = list('abcde')
  >>> s.insert(-1, 'f'); del s[-1]
  >>> s
  ['a', 'b', 'c', 'd', 'f']

I think the behavior can be made explainable and also be useful for common cases, but there is likely no getting around odd looking results with negative index insertions into bounded deques already at their maximum size.
Date User Action Args
2016-01-27 18:31:20rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, vstinner, python-dev, serhiy.storchaka
2016-01-27 18:31:20rhettingersetmessageid: <>
2016-01-27 18:31:20rhettingerlinkissue26194 messages
2016-01-27 18:31:20rhettingercreate