Skip to content

Honor zero maxlen when constructing a PDeque - #340

Open
Mrun25 wants to merge 2 commits into
tobgu:masterfrom
Mrun25:fix/zero-maxlen-deque
Open

Mrun25 wants to merge 2 commits into
tobgu:masterfrom
Mrun25:fix/zero-maxlen-deque

Conversation

@Mrun25

@Mrun25 Mrun25 commented Oct 25, 2026

Copy link
Copy Markdown

A nonempty iterable passed to pdeque(..., maxlen=0) currently remains in the deque. The constructor's t[-maxlen:] becomes t[0:], retaining every value. Subsequent appends can then grow the supposedly zero-capacity deque.

Use an empty prefix slice for zero bounds while retaining the existing suffix slice for positive bounds. The iterable is still consumed, False retains its accepted integer-zero behavior, and non-integral zero bounds still raise TypeError.

Add six parameterized regressions covering empty, singleton and multi-element generator inputs with 0 and False, input consumption, length, retained maxlen, both append/extend directions and pickle round trips. Also pin rejection of maxlen=0.0. Four new cases fail on the unchanged source; the two empty-input controls pass.

Validation on Linux:

  • CPython 3.10.12 and 3.13.16, compiled C extension: 643 passed, 1 existing skip each.
  • Both versions with PYRSISTENT_NO_C_EXTENSION=1: 542 passed, 102 existing C-extension skips each.
  • Module doctests: all 80 passed on both versions.
  • Wheel and sdist build on CPython 3.10; git diff --check: passed.

The existing Hypothesis collection warning remains. Other Python versions, PyPy, platforms, hosted CI and the memory-profile job were not run locally.

Related to #318, which was closed without a fix. This does not change the remove/reverse maxlen behavior or the separate slicing/rotation proposals.

AI-assisted investigation, implementation and testing.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 12:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants