Skip to content

Commit 7664f68

Browse files
authored
Release v1.3.0 (#19)
* Closes #17: Add default fallback (#18) * Add default fallback * Update changelog * Version fix * Fix test * Bump version
1 parent 6fddb47 commit 7664f68

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

docs/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v1.3.0
4+
5+
* Fix typing error ([#15](https://github.com/austind/retryhttp/pull/15))
6+
* Add default fallback wait strategy [`tenacity.wait_random_exponential`][] to [`retryhttp.wait_from_header`][] and [`retryhttp.wait_retry_after`][] ([#17](https://github.com/austind/retryhttp/pull/))
7+
38
## v1.2.0
49

510
* Added `wait_max` argument to [`retryhttp.wait_from_header`][] and [`retryhttp.wait_retry_after`][], which defaults to 120.0 seconds.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-backend="setuptools.build_meta"
1010

1111
[project]
1212
name = "retryhttp"
13-
version = "1.2.0"
13+
version = "1.3.0"
1414
description = "Retry potentially transient HTTP errors in Python."
1515
license = {file = "LICENSE"}
1616
readme = "README.md"

retryhttp/_wait.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class wait_from_header(wait_base):
3232
program will hang if the server responds with an excessive wait value.
3333
fallback (wait_base): Wait strategy to use if `header` is not present,
3434
or unable to parse to a `float` value, or if value parsed from header
35-
exceeds `wait_max`. Defaults to `None`.
35+
exceeds `wait_max`. Defaults to `tenacity.wait_exponential`.
3636
3737
Raises:
3838
ValueError: If `fallback` is `None`, and any one of the following is true:
@@ -47,7 +47,7 @@ def __init__(
4747
self,
4848
header: str,
4949
wait_max: Union[PositiveFloat, PositiveInt, None] = 120.0,
50-
fallback: Optional[wait_base] = None,
50+
fallback: Optional[wait_base] = wait_exponential(),
5151
) -> None:
5252
self.header = header
5353
self.wait_max = float(wait_max) if wait_max else None
@@ -69,7 +69,9 @@ def _get_wait_value(self, retry_state: RetryCallState) -> float:
6969
if retry_state.outcome:
7070
exc = retry_state.outcome.exception()
7171
if isinstance(exc, get_default_http_status_exceptions()):
72-
value = exc.response.headers.get(self.header, "")
72+
value = exc.response.headers.get(self.header)
73+
if value is None:
74+
raise ValueError(f"Header not present: {self.header}")
7375
if re.match(r"^\d+$", value):
7476
return float(value)
7577
else:
@@ -115,7 +117,7 @@ class wait_retry_after(wait_from_header):
115117
program will hang if the server responds with an excessive wait value.
116118
fallback (wait_base): Wait strategy to use if `header` is not present,
117119
or unable to parse to a `float` value, or if value parsed from header
118-
exceeds `wait_max`. Defaults to `None`.
120+
exceeds `wait_max`. Defaults to `tenacity.wait_exponential()`.
119121
120122
Raises:
121123
ValueError: If `fallback` is `None`, and any one of the following is true:
@@ -129,7 +131,7 @@ class wait_retry_after(wait_from_header):
129131
def __init__(
130132
self,
131133
wait_max: Union[PositiveFloat, PositiveInt, None] = 120.0,
132-
fallback: Optional[wait_base] = None,
134+
fallback: Optional[wait_base] = wait_exponential(),
133135
) -> None:
134136
super().__init__(header="Retry-After", wait_max=wait_max, fallback=fallback)
135137

tests/test_wait.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@retry(
1313
retry=retry_if_server_error(),
14-
wait=wait_from_header(header="Retry-After", wait_max=5),
14+
wait=wait_from_header(header="Retry-After", wait_max=5, fallback=None),
1515
stop=stop_after_attempt(3),
1616
)
1717
def planned_downtime_impatient_no_fallback():

0 commit comments

Comments
 (0)