Skip to content

Replace Extensions with RequestExtensions and ResponseExtensions TypedDicts#1020

Open
Kludex wants to merge 1 commit into
replace-mypy-by-pyrightfrom
request-response-extensions
Open

Replace Extensions with RequestExtensions and ResponseExtensions TypedDicts#1020
Kludex wants to merge 1 commit into
replace-mypy-by-pyrightfrom
request-response-extensions

Conversation

@Kludex
Copy link
Copy Markdown
Member

@Kludex Kludex commented Jun 3, 2026

Replaces the loosely-typed Extensions = MutableMapping[str, Any] alias in httpcore2 with explicit RequestExtensions and ResponseExtensions TypedDicts, derived from the extension keys the backends actually read and write.

  • RequestExtensions: timeout (a nested Timeout TypedDict with connect/read/write/pool), sni_hostname, trace, target. Declared with extra_items=Any so user/middleware keys still type-check.
  • ResponseExtensions: http_version, reason_phrase, network_stream, stream_id, also extra_items=Any.
  • extra_items= (PEP 728) lands in stdlib typing only in Python 3.15, so TypedDict is imported from typing_extensions below 3.15 and from typing at/above it; the dependency carries a matching python_version < '3.15' marker.
  • Updates _api.py and the sync/async interfaces.py to the new types, and threads RequestExtensions through httpx2.Request.

Note: scripts/check is 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.

@Kludex
Copy link
Copy Markdown
Member Author

Kludex commented Jun 3, 2026

It may make sense to have a single RequestExtensions and ResponseExtensions instead of having 2 of them. And that will probably solve the remaining type checker issues...

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +39 to +41
http_version: typing.Required[bytes]
reason_phrase: bytes
network_stream: typing.Required[typing.Any]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 9 files

Re-trigger cubic

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