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 <1453919480.46.0.66067542494.issue26194@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
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: <1453919480.46.0.66067542494.issue26194@psf.upfronthosting.co.za>
2016-01-27 18:31:20rhettingerlinkissue26194 messages
2016-01-27 18:31:20rhettingercreate