Skip to content

Normalize PDeque rotation steps before popping - #336

Open
ac1982 wants to merge 1 commit into
tobgu:masterfrom
ac1982:fix/deque-large-rotation
Open

ac1982 wants to merge 1 commit into
tobgu:masterfrom
ac1982:fix/deque-large-rotation

Conversation

@ac1982

@ac1982 ac1982 commented Oct 8, 2026

Copy link
Copy Markdown

pdeque([0, 1, 2]).rotate(4) currently returns the original order instead of [2, 0, 1]: popping clamps at the deque length, so oversized rotations lose their remainder. Negative rotations have the same problem, and arbitrarily large integer steps fail in islice().

Normalize the step count modulo the length before popping, preserving the direction so small left rotations remain small. Return an empty deque unchanged after validating the step via the integer-index protocol.

Tests compare positive and negative rotations with collections.deque, including zero steps, multiple full turns, bounded and empty deques, unchanged original values, very large integers, and index-protocol inputs. The final regression suite has 13 failures on the base. After the fix on Linux / Python 3.12:

  • Full suite: 700 passed, 1 skipped.
  • Pure-Python suite: 599 passed, 102 skipped.
  • All 80 module doctests passed.
  • Wheel and sdist builds passed.

This branch is based directly on master. It is independent of #335's slicing fix and leaves #331's remove/reverse maxlen fix untouched.

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.

1 participant