Repository navigation
Conversation
PDeque threads its maxlen into every structural result except remove() and reverse(), which constructed the new PDeque without the maxlen argument and thus defaulted it to None. A bounded deque therefore became unbounded after either operation, so later appends could grow it past its declared maximum length. Pass self._maxlen through in both methods to match the other operations.
dualfroz
force-pushed
the
dualfroz/pdeque-maxlen-preserve
branch
from
September 5, 2026 23:10
b4f63bb to
69c453e
Compare
This was referenced Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A bounded
PDeque(created withmaxlen) loses its bound when passed throughremove()orreverse():Because the bound is silently dropped, the result no longer enforces its
maximum length, so subsequent appends can grow it past the declared
maxlen:Root cause
pyrsistent/_pdeque.py.PDeque.__new__acceptsmaxlen=Noneas a default.Every structural method threads
self._maxleninto the new instance(
pop,popleft,append,extend, ...), except two:remove()built its results withPDeque(..., self._length - 1), omittingthe
maxlenargument (both the left-list and the right-list branches).reverse()built its result withPDeque(self._right_list, self._left_list, self._length), omittingmaxlen.Both therefore defaulted
maxlentoNone.Fix
Pass
self._maxlenthrough in both methods, matching every other structuraloperation on
PDeque.Test
tests/deque_test.py::test_remove_preserves_maxlenand::test_reverse_preserves_maxlenassert the returned deque keepsmaxlen == 3and stays bounded across a following append. (
PDeque.__eq__compares only theelements and ignores
maxlen, so the tests check.maxlendirectly.)Both fail on the current
master(assert None == 3) and pass with the fix.