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.

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

1313 import random
1414 import sys
1515 import time
16+import warnings
1617 from collections import defaultdict
1718 from collections.abc import Callable, Coroutine, Iterator
1819 from contextlib import contextmanager
209210 https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
210211 """
211212
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+
212223 def decorator(f: Callable[P, R]) -> Callable[P, R]:
213224 @functools.wraps(f)
214225 def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
249260 ) -> Callable[
250261 [Callable[P, Coroutine[None, None, R]]], Callable[P, Coroutine[None, None, R]]
251262 ]:
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+
252273 def decorator(
253274 f: Callable[P, Coroutine[None, None, R]]
254275 ) -> Callable[P, Coroutine[None, None, R]]:

The check that tells the two apart

failpass·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.