Replace Extensions with RequestExtensions and ResponseExtensions TypedDicts#1020
Replace Extensions with RequestExtensions and ResponseExtensions TypedDicts#1020Kludex wants to merge 1 commit into
Extensions with RequestExtensions and ResponseExtensions TypedDicts#1020Conversation
|
It may make sense to have a single |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83a238e92c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| http_version: typing.Required[bytes] | ||
| reason_phrase: bytes | ||
| network_stream: typing.Required[typing.Any] |
There was a problem hiding this comment.
Use typing_extensions.Required for Python 3.10
Because httpcore2 still advertises/supports Python 3.10, these annotations cannot refer to typing.Required: Required was added to stdlib typing in Python 3.11. In Python 3.10 type checking this file reports typing.Required as an unknown member, and runtime consumers that resolve annotations with get_type_hints(..., include_extras=True) will fail to evaluate ResponseExtensions. Import Required from typing_extensions alongside TypedDict for the pre-3.11/3.15 path.
Useful? React with 👍 / 👎.
Replaces the loosely-typed
Extensions = MutableMapping[str, Any]alias inhttpcore2with explicitRequestExtensionsandResponseExtensionsTypedDicts, derived from the extension keys the backends actually read and write.RequestExtensions:timeout(a nestedTimeoutTypedDict withconnect/read/write/pool),sni_hostname,trace,target. Declared withextra_items=Anyso user/middleware keys still type-check.ResponseExtensions:http_version,reason_phrase,network_stream,stream_id, alsoextra_items=Any.extra_items=(PEP 728) lands in stdlibtypingonly in Python 3.15, soTypedDictis imported fromtyping_extensionsbelow 3.15 and fromtypingat/above it; the dependency carries a matchingpython_version < '3.15'marker._api.pyand the sync/asyncinterfaces.pyto the new types, and threadsRequestExtensionsthroughhttpx2.Request.Note:
scripts/checkis not fully green yet (pre-existing items unrelated to this typing change).AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.