Skip to content

Fix Interval.range hang on a zero or wrong-sign amount - #1081

Open
ekanshul wants to merge 1 commit into
python-pendulum:masterfrom
ekanshul:fix-1080-interval-range-zero-amount
Open

ekanshul wants to merge 1 commit into
python-pendulum:masterfrom
ekanshul:fix-1080-interval-range-zero-amount

Conversation

@ekanshul

@ekanshul ekanshul commented Nov 2, 2026

Copy link
Copy Markdown

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

Fixes #1080

Interval.range(unit, amount) used amount as both the step and the loop increment with no validation. amount=0 therefore yielded the start forever (start.add(days=0) never moves, so start <= end stays true). A negative amount on a forward interval walked away from the end instead of terminating.

Reject a zero amount with ValueError. A negative amount whose sign does not match the interval direction now yields an empty iterator, the same way Python's range() does. Existing positive-amount ranges are unchanged.

range() treated amount as both the step and the termination
increment with no validation, so amount=0 yielded the start
forever and a mismatched sign walked away from the end.

Reject a zero amount with ValueError. A negative amount whose
sign does not match the interval direction now yields an empty
iterator, matching Python range().

This branch has not been deployed

No deployments
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.

Interval.range() hangs forever on a zero (or wrong-sign) step

1 participant