Repository navigation
Conversation
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().
| ``` | ||
|
|
||
| `amount` must be a non-zero integer. A zero amount raises `ValueError`. | ||
| A negative amount whose sign does not match the interval direction |
There was a problem hiding this comment.
Could we clarify this for inverted intervals? If dt2 is later than dt1, interval(dt2, dt1).range("days", -1) returns an empty iterator even though the step points in the same direction as the interval. A positive amount already iterates backwards there.
For equal endpoints, the loop yields that endpoint once even with -1. A short example for each case would make the intended behavior clearer.
|
Clarified the direction rules with examples: a positive amount follows the interval direction, so an inverted interval walks backwards; a negative amount moves away from the end and yields no values when the endpoints differ. Equal endpoints are yielded once with either sign. Added equal-endpoint tests and corrected the implementation comments. All 46 interval tests and the configured hooks for changed files pass. Codex assisted with this revision and validation. |
Pull Request Check List
Fixes #1080
Interval.range(unit, amount)usedamountas both the step and the loop increment with no validation.amount=0therefore yielded the start forever (start.add(days=0)never moves, sostart <= endstays 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'srange()does. Existing positive-amount ranges are unchanged.