Skip to content

pdeque ignores maxlen=0 during construction #318

@T90REAL

Description

@T90REAL

pyrsistent.pdeque now accepts the maxlen=0 setting, but it does not handle it correctly:

from pyrsistent import pdeque

dq = pdeque([0], maxlen=0)
print(dq, len(dq))        # expected pdeque([], maxlen=0) and 0
dq = dq.append(1)
print(dq, len(dq))        # expected still length 0, but length becomes 2
pdeque([0], maxlen=0) 1
pdeque([0, 1], maxlen=0) 2

Although maxlen=0 is not common, it is still an inconsistent behavior. The problem originates in _pdeque.py: during construction t = t[-maxlen:] leaves t unchanged for maxlen=0, so _length is set incorrectly. A fix would be to special-case maxlen=0.

Note: This issue was identified by an automated testing tool for academic research and manually verified. If you have any concerns about this type of reporting, please let me know, and I will adjust my workflow accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions