Title: fix: validate the amount in Interval.range (zero/negative hang or run away) by rahul05ranjan · Pull Request #1090 · python-pendulum/pendulum · GitHub
Open Graph Title: fix: validate the amount in Interval.range (zero/negative hang or run away) by rahul05ranjan · Pull Request #1090 · python-pendulum/pendulum
X Title: fix: validate the amount in Interval.range (zero/negative hang or run away) by rahul05ranjan · Pull Request #1090 · python-pendulum/pendulum
Description: Interval.range(unit, amount) accepts any integer amount, including 0 — which produces a generator that yields the same starting value forever and never reaches its stated end: it = pendulum.interval(pendulum.datetime(2026, 1, 1), pendulum.datetime(2026, 2, 1)).range("days", 0) # next(it) -> 2026-01-01 # next(it) -> 2026-01-01 (forever; start = self.start.add(days=0) never moves) The loop's advance step (add(**{unit: i}) with i stuck at 0) and its termination check (start <= end) both depend on amount, so any caller that consumes the generator without an independent bound — a plain for loop, list(...) — hangs at full CPU with no way to recover. A caller that builds the step from user/config input can be made to hang a worker indefinitely. A related case, a wrong-sign amount (e.g. -1 on a forward interval), does not hang but runs away unbounded in the opposite direction from the stated end — the same missing validation. Fix: reject non-positive amounts with ValueError. The direction is already applied internally (add/le vs subtract/ge per the interval's orientation), so the step magnitude must be positive in both directions. >>> list(p.range("days", 0)) ValueError: amount must be a positive integer, got 0 Fixes #1080. Verification (system Python 3.13, wheels on the path, nothing installed): Both failure modes demonstrated on unpatched master@e06dace: amount=0 repeats the start indefinitely (islice of an infinite generator), amount=-1 yields 2026-01-01, 2025-12-31, 2025-12-30 … running backward, never reaching the end. New tests in tests/interval/test_range.py (zero and negative amount → ValueError): both fail with the infinite/escaping behavior on unpatched master, pass with this change. tests/interval, tests/datetime, tests/parsing, tests/formatting, tests/date, tests/time: 1104 passed, zero regressions.
Open Graph Description: Interval.range(unit, amount) accepts any integer amount, including 0 — which produces a generator that yields the same starting value forever and never reaches its stated end: it = pendulum.interva...
X Description: Interval.range(unit, amount) accepts any integer amount, including 0 — which produces a generator that yields the same starting value forever and never reaches its stated end: it = pendulum.interva...
Opengraph URL: https://github.com/python-pendulum/pendulum/pull/1090
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5d3ecb0b-a61f-eba9-93ef-fe0016b7b0ee |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D1F8:5EC22:3B189D:535E1B:6B046E92 |
| html-safe-nonce | 30884dfd190c93f36a60203a54f280e17668d5ecd347c2be7711357032a4b4d1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUY4OjVFQzIyOjNCMTg5RDo1MzVFMUI6NkIwNDZFOTIiLCJ2aXNpdG9yX2lkIjoiNzE0NDc3MDk0Mjk5OTQ5MDE5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 141d604c3df294d2fb215cc7ea7c80c9baee4cdda9b1433bbffb6cd90fa7f806 |
| hovercard-subject-tag | pull_request:5223790033 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-pendulum/pendulum/pull/1090/files |
| twitter:image | https://avatars.githubusercontent.com/u/11793455?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/11793455?s=400&v=4 |
| og:image:alt | Interval.range(unit, amount) accepts any integer amount, including 0 — which produces a generator that yields the same starting value forever and never reaches its stated end: it = pendulum.interva... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git |
| octolytics-dimension-user_id | 191041900 |
| octolytics-dimension-user_login | python-pendulum |
| octolytics-dimension-repository_id | 62095504 |
| octolytics-dimension-repository_nwo | python-pendulum/pendulum |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 62095504 |
| octolytics-dimension-repository_network_root_nwo | python-pendulum/pendulum |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width