From 0f4d8441e56e7b20ec6d7a40023505b888247b79 Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Wed, 5 Feb 2025 13:34:27 -0600 Subject: [PATCH 1/7] Add note --- .gitignore | 4 +++- docs/guide.md | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a2690e6..933dd9f 100644 --- a/.gitignore +++ b/.gitignore @@ -161,4 +161,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -.vscode/ \ No newline at end of file +.vscode/ + +hack.py \ No newline at end of file diff --git a/docs/guide.md b/docs/guide.md index 99ca254..817b63c 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -53,6 +53,9 @@ def get_example(): response.raise_for_status() ``` +!!! note + `retryhttp` works by catching exceptions, so your code must raise those exceptions. Most of the time, all you need is to call `response.raise_for_status()`. Be sure not to catch those exceptions in your own `try..except` block. + ## Advanced Usage You don't have to use the [`retryhttp.retry`][] decorator, which is provided purely for convenience. If you prefer, you can use [`tenacity.retry`](https://tenacity.readthedocs.io/en/latest/api.html#tenacity.retry) and roll your own approach. From 5bf7a078bb76c6f6c4108652363f9dbdd7e03a8f Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Tue, 15 Apr 2025 07:46:40 -0500 Subject: [PATCH 2/7] Update changelog --- docs/changelog.md | 4 ++++ hack.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 hack.py diff --git a/docs/changelog.md b/docs/changelog.md index cc6103c..66f2fde 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Changelog +## v1.3.2 + +* Bugfix: Don't pass `stop`, `wait`, and `retry` keyword arguments from [`retryhttp.retry`][] on to `tenacity.retry()` ([#23](https://github.com/austind/retryhttp/issues/23)) + ## v1.3.1 * Fixed all outstanding mypy errors. ([#20](https://github.com/austind/retryhttp/issues/20) diff --git a/hack.py b/hack.py new file mode 100644 index 0000000..958e19e --- /dev/null +++ b/hack.py @@ -0,0 +1,46 @@ +from uuid import UUID +from pydantic import BaseModel +import httpx +from retryhttp._retry import retry + + +class Payload(BaseModel): + uuid: UUID + id: int + user_id: int + user_uuid: UUID + + +class Defaults(BaseModel): + timeout: int = 3 + backoff: bool = True + + +defaults1 = { + "timeout": 5, + "backoff": True, +} + +defaults2 = Defaults().model_dump() + + +@retry(**defaults1) +def get_example1(x: int) -> Payload: + response = httpx.get("https://example.com/") + response.raise_for_status() + + return Payload(**response.json()) + + +x = get_example1(1).user_id + + +@retry(**defaults2) +def get_example2(x: int) -> Payload: + response = httpx.get("https://example.com/") + response.raise_for_status() + + return Payload(**response.json()) + + +x = get_example2(1).user_id From dcb3a3b10694276f921aed433991f4b558b9d0f7 Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Tue, 15 Apr 2025 07:47:23 -0500 Subject: [PATCH 3/7] remove hack.py --- hack.py | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 hack.py diff --git a/hack.py b/hack.py deleted file mode 100644 index 958e19e..0000000 --- a/hack.py +++ /dev/null @@ -1,46 +0,0 @@ -from uuid import UUID -from pydantic import BaseModel -import httpx -from retryhttp._retry import retry - - -class Payload(BaseModel): - uuid: UUID - id: int - user_id: int - user_uuid: UUID - - -class Defaults(BaseModel): - timeout: int = 3 - backoff: bool = True - - -defaults1 = { - "timeout": 5, - "backoff": True, -} - -defaults2 = Defaults().model_dump() - - -@retry(**defaults1) -def get_example1(x: int) -> Payload: - response = httpx.get("https://example.com/") - response.raise_for_status() - - return Payload(**response.json()) - - -x = get_example1(1).user_id - - -@retry(**defaults2) -def get_example2(x: int) -> Payload: - response = httpx.get("https://example.com/") - response.raise_for_status() - - return Payload(**response.json()) - - -x = get_example2(1).user_id From d0aab2880d4e488dc8c711cdf7ec3035f064cf2e Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Tue, 15 Apr 2025 07:49:55 -0500 Subject: [PATCH 4/7] bump version and line length --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e61465f..e32e1f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ build-backend="setuptools.build_meta" [project] name = "retryhttp" -version = "1.3.1" +version = "1.3.2" description = "Retry potentially transient HTTP errors in Python." license = {file = "LICENSE"} readme = "README.md" @@ -79,7 +79,7 @@ Issues = "https://github.com/austind/retryhttp/issues" packages = ["retryhttp"] [tool.ruff] -line-length = 88 +line-length = 100 indent-width = 4 target-version = "py38" From a361fc4873b1ed979a7e89a473f7e2be634cb5bd Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Tue, 15 Apr 2025 07:51:01 -0500 Subject: [PATCH 5/7] Move setuptools section --- pyproject.toml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e32e1f0..ce53186 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,3 @@ -[build-system] -# Minimum requirements for the build system to execute. -# PEP 508 specifications for PEP 518. -# Banned setuptools versions have well-known issues -requires = [ - "setuptools >= 21.0.0,!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0", # PSF/ZPL - "setuptools_scm[toml]>=3.4", -] -build-backend="setuptools.build_meta" [project] name = "retryhttp" @@ -75,6 +66,16 @@ Homepage = "https://github.com/austind/retryhttp" Repository = "https://github.com/austind/retryhttp.git" Issues = "https://github.com/austind/retryhttp/issues" +[build-system] +# Minimum requirements for the build system to execute. +# PEP 508 specifications for PEP 518. +# Banned setuptools versions have well-known issues +requires = [ + "setuptools >= 21.0.0,!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0", # PSF/ZPL + "setuptools_scm[toml]>=3.4", +] +build-backend="setuptools.build_meta" + [tool.setuptools] packages = ["retryhttp"] From a31b65ea1d6099150e1adb5db136d8dd025d9a18 Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Tue, 15 Apr 2025 07:52:26 -0500 Subject: [PATCH 6/7] readme tweaks --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36d64a6..3ba0d59 100644 --- a/README.md +++ b/README.md @@ -62,4 +62,4 @@ def example(): ## Contributing -Contributions welcome! Open a discussion and let's chat about your idea. Looking forward to working with you! +Contributions welcome! Bug fixes and minor tweaks can jump straight to a [pull request](https://github.com/austind/retryhttp/compare). For more involved changes, [open an issue](https://github.com/austind/retryhttp/issues/new/choose) and let's chat about your idea. Looking forward to working with you! From dae21c46af9f9382697e173082d02a26e0817b17 Mon Sep 17 00:00:00 2001 From: Austin de Coup-Crank Date: Tue, 15 Apr 2025 07:57:54 -0500 Subject: [PATCH 7/7] readme tweaks --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3ba0d59..2d21657 100644 --- a/README.md +++ b/README.md @@ -19,22 +19,21 @@ Several HTTP errors are often transient, and might succeed if retried: This project aims to simplify retrying these, by extending [`tenacity`](https://tenacity.readthedocs.io/) with custom retry and wait strategies, as well as a custom decorator. Defaults are sensible for most use cases, but are fully customizable. -Supports exceptions raised by both [`requests`](https://docs.python-requests.org/en/latest/index.html) and [`httpx`](https://python-httpx.org/). +Supports both [`requests`](https://docs.python-requests.org/en/latest/index.html) and [`httpx`](https://python-httpx.org/) natively, but could be customized to use with any library that raises exceptions for the conditions listed above. ## Install Install from PyPI: ```sh -# Supports both HTTPX and requests -pip install retryhttp +pip install retryhttp # Supports both HTTPX and requests ``` -You can also install support for only HTTPX or requests: +You can also install support for only HTTPX or requests, if you would rather not install unnecessary dependencies: ```sh -pip install retryhttp[httpx] # Supports only HTTPX -pip install retryhttp[requests] # Supports only requests +pip install retryhttp[httpx] # Supports only HTTPX +pip install retryhttp[requests] # Supports only requests ``` Or, install the latest development snapshot from git: @@ -49,8 +48,8 @@ pip install git+https://github.com/austind/retryhttp.git@develop import httpx from retryhttp import retry -# Retries retryable status codes (429, 500, 502, 503, 504), network errors, -# and timeouts, up to 3 times, with appropriate wait strategies for each +# Retries safely retryable status codes (429, 500, 502, 503, 504), network errors, +# and timeouts, up to a total of 3 times, with appropriate wait strategies for each # type of error. All of these behaviors are customizable. @retry def example(): @@ -62,4 +61,4 @@ def example(): ## Contributing -Contributions welcome! Bug fixes and minor tweaks can jump straight to a [pull request](https://github.com/austind/retryhttp/compare). For more involved changes, [open an issue](https://github.com/austind/retryhttp/issues/new/choose) and let's chat about your idea. Looking forward to working with you! +Contributions welcome! Bug fixes and minor tweaks can jump straight to a [pull request](https://github.com/austind/retryhttp/compare). For more involved changes, [open an issue](https://github.com/austind/retryhttp/issues/new/choose) and let's chat about your idea. Thanks for your contribution!