Skip to content

Allow default_encoding callable to return None#951

Merged
Kludex merged 2 commits into
mainfrom
fix/default-encoding-callable-optional
May 17, 2026
Merged

Allow default_encoding callable to return None#951
Kludex merged 2 commits into
mainfrom
fix/default-encoding-callable-optional

Conversation

@Kludex

@Kludex Kludex commented May 17, 2026

Copy link
Copy Markdown
Member

Summary

Widens default_encoding's callable signature from Callable[[bytes], str] to Callable[[bytes], str | None]. Response.encoding already handles a None return via the encoding or "utf-8" fallback at the end of the property, and our own docs/advanced/text-encodings.md example uses chardet.detect(content).get("encoding"), which can return None.

Backport of upstream encode/httpx#3079 by @JelleZijlstra (still open upstream, but the change is straightforwardly correct).

Test plan

  • mypy passes
  • CI green

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

@Kludex Kludex force-pushed the fix/default-encoding-callable-optional branch from ccb29ca to 8d89826 Compare May 17, 2026 05:34
@Kludex Kludex enabled auto-merge (squash) May 17, 2026 05:35
@Kludex Kludex disabled auto-merge May 17, 2026 05:35
@Kludex Kludex changed the title Allow default_encoding callable to return None Allow default_encoding callable to return None May 17, 2026
@Kludex Kludex enabled auto-merge (squash) May 17, 2026 05:35
@Kludex Kludex merged commit 39ddd28 into main May 17, 2026
11 checks passed
@Kludex Kludex deleted the fix/default-encoding-callable-optional branch May 17, 2026 05:36
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