Skip to content

Allow status predicates for retries#77

Closed
mzl2233 wants to merge 1 commit into
will-ockmore:mainfrom
mzl2233:fix/status-predicate
Closed

Allow status predicates for retries#77
mzl2233 wants to merge 1 commit into
will-ockmore:mainfrom
mzl2233:fix/status-predicate

Conversation

@mzl2233
Copy link
Copy Markdown

@mzl2233 mzl2233 commented May 14, 2026

Adds support for passing a predicate to status_forcelist while preserving the existing iterable behavior. The retry status check now calls the predicate when one is provided, and the new regression test covers retrying 5xx responses without enumerating every status code. Verified with python3 -m pytest tests/test_retry.py -q, python3 -m mypy httpx_retries tests, and git diff --check.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (999e2aa) to head (166f0de).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #77   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines         1001      1015   +14     
=========================================
+ Hits          1001      1015   +14     
Files with missing lines Coverage Δ
httpx_retries/retry.py 100.00% <100.00%> (ø)
tests/test_retry.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Owner

@will-ockmore will-ockmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to put this together @mzl2233 .

Thinking about the exact semantics here, I think that adding a status predicate is probably more hassle than it's worth. It complicates the typing and breaks usage for anyone introspecting status_forcelist.

I was thinking about if we could add it as a separate parameter, but then we have to deal with which takes precedence. It's easier to avoid it entirely.

Apologies but I don't think we can accept this at the moment.

Comment thread tests/test_retry.py
Comment on lines -36 to 38
assert HTTPStatus.INTERNAL_SERVER_ERROR in retry.status_forcelist
assert HTTPStatus.BAD_GATEWAY in retry.status_forcelist
assert retry.is_retryable_status_code(HTTPStatus.INTERNAL_SERVER_ERROR)
assert retry.is_retryable_status_code(HTTPStatus.BAD_GATEWAY)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Losing the ability to use in retry.status_forcelist would be sad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants