Skip to content

refactor: delete the unreachable None branch in retry-after parsing - #141

Merged
lesnik512 merged 1 commit into
mainfrom
chore/followups
Sep 27, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
chore/followups

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Delete the if parsed is None: return None branch (and its # pragma: no cover) in _parse_retry_after, src/httpware/middleware/resilience/retry.py.

Why

email.utils.parsedate_to_datetime cannot return None on any interpreter httpware supports (requires-python >=3.11), so the branch was dead code that coverage had to be told to ignore.

Evidence

  • CPython source (inspect.getsource on 3.11.16, 3.12.13, 3.13.15, 3.14.7): the function has exactly two return statements, and both return a datetime.datetime(...). When _parsedate_tz yields None it does raise ValueError('Invalid date value or format ...'). 3.13+ also turns OverflowError from the datetime constructor into ValueError.
  • CPython docs (email.utils): the function "on success returns a datetime; otherwise ValueError is raised".
  • Runtime probe on 3.11, 3.12, 3.13, 3.14 and 3.14t with 13 malformed or edge-case inputs ("", "garbage", day 32, a bad month, hour 25, NUL, a huge year, a missing or unknown zone, -0000). Every call either raised or returned a datetime, and none returned None.

Checks (local)

  • just install: no lockfile change
  • just lint-ci: pass
  • just test-ci: 819 passed, coverage 100.00%

@lesnik512
lesnik512 merged commit 60d340a into main Sep 27, 2026
13 checks passed
@lesnik512
lesnik512 deleted the chore/followups branch September 27, 2026 16:52
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.

1 participant