feat: add min param and timedelta support to wait_exponential_jitter#628
Conversation
…tter` `wait_exponential` already supports `min` and `timedelta` for min/max. `wait_exponential_jitter` lacked both, which was an inconsistency users asked for in #426. - Accept `timedelta` for `max`, `jitter`, and `min` parameters - Add `min` parameter to set a minimum wait time floor - Convert all time parameters via `_utils.to_seconds()` in `__init__` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Change-Id: Ic02ae68b863cc0d1cd5a3b7874006c193c0c14a8
Merge Queue Status
This pull request spent 6 seconds in the queue, with no time running CI. Required conditions to merge |
There was a problem hiding this comment.
Pull request overview
Adds missing parity between wait_exponential and wait_exponential_jitter by introducing a minimum wait floor and supporting datetime.timedelta inputs for key time parameters.
Changes:
- Add
minparameter towait_exponential_jitterand apply it as a lower bound on computed waits. - Accept
timedeltaformax,jitter, andminby normalizing via_utils.to_seconds()in__init__. - Expand test coverage for the new
minbehavior andtimedeltainputs; add a release note entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tenacity/wait.py |
Extends wait_exponential_jitter API and clamps waits using the new min floor; normalizes time params via _utils.to_seconds(). |
tests/test_tenacity.py |
Adds tests for min floor behavior and timedelta parameter handling. |
releasenotes/notes/wait-exponential-jitter-min-timedelta-a8e3c1f4b7d29e50.yaml |
Documents the new min parameter and timedelta support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| https://cloud.google.com/storage/docs/retry-strategy | ||
|
|
||
| The wait time is min(initial * 2**n + random.uniform(0, jitter), maximum) | ||
| The wait time is max(min, min(initial * 2**n + random.uniform(0, jitter), maximum)) |
There was a problem hiding this comment.
Docstring formula hard-codes 2**n, but the implementation uses the configurable exp_base (self.exp_base ** (attempt_number - 1)). The docstring should reflect exp_base**n (or similar) to avoid misleading users who pass a non-default exp_base.
| The wait time is max(min, min(initial * 2**n + random.uniform(0, jitter), maximum)) | |
| The wait time is max(min, min(initial * exp_base**n + random.uniform(0, jitter), maximum)) |
wait_exponentialalready supportsminandtimedeltafor min/max.wait_exponential_jitterlacked both, which was an inconsistency usersasked for in #426.
timedeltaformax,jitter, andminparametersminparameter to set a minimum wait time floor_utils.to_seconds()in__init__Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com