[issue26194] Undefined behavior for deque.insert() when len(d) == maxlen

Tim Peters report at bugs.python.org
Wed Jan 27 13:56:05 EST 2016


Tim Peters added the comment:

I'd raise an exception when trying to insert into a bounded deque that's already full.  There's simply no way to guess what was _intended_; it's dead easy for the user to implement what they _do_ intend (first make room by deleting the specific item they no longer want); and I can't think of a use case compelling enough to justify whatever arbitrary non-exceptional behavior may be implemented instead.

WRT the behavior you settled on, sure, it's explainable.  That doesn't imply it's useful, though ;-)  I'd rather have an exception.  It's plain bizarre that after

    d.insert(i, x)

one can't even rely on

    assert any(y is x for y in d)

succeeding.  Implementing behavior that allows that invariant to fail is _really_ user-unfriendly ;-)

In contrast, what .append() and .appendleft() do for a full bounded deque are compelling (and don't violate the weak invariant above).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26194>
_______________________________________


More information about the Python-bugs-list mailing list