Raymond Hettinger added the comment:
Since slicing is going to be added to deques, it is worth thinking about what
the behavior should be there as well:
d = deque('abcde', maxlen=7)
d[3:4] = 'efghijklm'
Side note: repetition behaves like extend() using maxlen to decide how much to
truncate from the left:
>>> from collections import deque
>>> d = deque('abcde', maxlen=8)
>>> d *= 2
>>> d
deque(['c', 'd', 'e', 'a', 'b', 'c', 'd', 'e'], maxlen=8)
Ideally, the deque API should be coherent and simple taken as a whole so that
the behaviors are consistent and predictable as possible even if the general
rules lead to some oddities in some uncommon cases.
One such general rule could be: "When maxlen is defined, operations proceed as
if the deque were unbounded and then truncation is applied to the left" (this
is like the rule in decimal where inputs to operations are treated as precise
and context rounding is applied after the operation). The general rule would
fit a mental models of "inserted new data is prioritized over old data", that
"maxlen is all about automatically evicting data to make room for the newer
data", and that "methods without 'left' in their name correspond to newest data
on the right and next to be evicted on the left".
----------
_______________________________________
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