Whole file
channable/opnieuw
The author described this change as “Raise a ``UserWarning`` when ``max_calls_total < 2``”. It counts as a record because the check below fails on the code as it stood at 2db14169b and passes on b973768ac, with nothing else changed between the two runs.
Projectchannable/opnieuw
Fix saved2023-11-14
Sharing licenceBSD-3-Clause · LICENSE
Change size+21 −0
What the code was meant to do, written into the code itself as a save note
Raise a ``UserWarning`` when ``max_calls_total < 2``
The change
| 13 | 13 | import random | |
| 14 | 14 | import sys | |
| 15 | 15 | import time | |
| 16 | + | import warnings | |
| 16 | 17 | from collections import defaultdict | |
| 17 | 18 | from collections.abc import Callable, Coroutine, Iterator | |
| 18 | 19 | from contextlib import contextmanager | |
| ⋯ | |||
| 209 | 210 | https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ | |
| 210 | 211 | """ | |
| 211 | 212 | ||
| 213 | + | if max_calls_total < 2: | |
| 214 | + | warnings.warn( | |
| 215 | + | "`max_calls_total` should at least be 2 for `opnieuw` to retry. " | |
| 216 | + | f"It is set to '{max_calls_total}'. If you want to retry without delay " | |
| 217 | + | "consider using `opnieuw.test_util.retry_immediately`. If you do not " | |
| 218 | + | "want any retries consider using `opnieuw.util.no_retries`", | |
| 219 | + | UserWarning, | |
| 220 | + | stacklevel=2, | |
| 221 | + | ) | |
| 222 | + | ||
| 212 | 223 | def decorator(f: Callable[P, R]) -> Callable[P, R]: | |
| 213 | 224 | @functools.wraps(f) | |
| 214 | 225 | def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: | |
| ⋯ | |||
| 249 | 260 | ) -> Callable[ | |
| 250 | 261 | [Callable[P, Coroutine[None, None, R]]], Callable[P, Coroutine[None, None, R]] | |
| 251 | 262 | ]: | |
| 263 | + | if max_calls_total < 2: | |
| 264 | + | warnings.warn( | |
| 265 | + | "`max_calls_total` should at least be 2 for `opnieuw` to retry. " | |
| 266 | + | f"It is set to '{max_calls_total}'. If you want to retry without delay " | |
| 267 | + | "consider using `opnieuw.test_util.retry_immediately`. If you do not " | |
| 268 | + | "want any retries consider using `opnieuw.util.no_retries`", | |
| 269 | + | UserWarning, | |
| 270 | + | stacklevel=2, | |
| 271 | + | ) | |
| 272 | + | ||
| 252 | 273 | def decorator( | |
| 253 | 274 | f: Callable[P, Coroutine[None, None, R]] | |
| 254 | 275 | ) -> Callable[P, Coroutine[None, None, R]]: | |
The check that tells the two apart
fail→pass·tests/test_opnieuw.py::TestWarningOnOneRetry::test_raise_warning_for_retry_once
Check file tests/test_opnieuw.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it2db14169bf87deab56ff767e955383b20412f7d7
Broken version dated2023-11-13
Moduleopnieuw.retries
Units changedretry, retry_async
Fingerprint140c1f61c8935945
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.