Raymond Hettinger added the comment:
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.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue26194>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com