Skip to content

fix: make generated clients type-check with httpx and mypy - #476

Merged
DamianCzajkowski merged 1 commit into
mainfrom
fix/http-client-protocol
Nov 2, 2026
Merged

DamianCzajkowski merged 1 commit into
mainfrom
fix/http-client-protocol

Conversation

@DamianCzajkowski

@DamianCzajkowski DamianCzajkowski commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #463

Problem

Since 0.19.0 a generated client fails type checking when users pass their own HTTP client, and also on its own optional-import fallbacks:

  1. HttpClient.post() declared json/data/files/headers as positional-or-keyword and ended with **kwargs: Any. httpx.Client.post/httpx.AsyncClient.post take everything after url as keyword-only and have no **kwargs, so mypy and pyright reject http_client=httpx.AsyncClient(...). The same applied to requests.Session, which the docs list as a compatible client.
  2. The websockets and opentelemetry fallbacks (ClientConnection = Any, Context = Any, …) only carried # ty: ignore[...], which mypy doesn't understand (fix(types): align ty suppressions for GraphQL and optional imports #427 replaced the previous # type: ignore[...]).

Changes

  • All 8 HttpClient protocols take request arguments as keyword-only and no longer require **kwargs. Base clients only call post() with keywords, so runtime behaviour is unchanged, and existing custom clients written against the old protocol still satisfy the new one.
  • Restored # type: ignore[misc,assignment,unused-ignore] on the fallback assignments. ty honours it too.
  • Updated the protocol snippets in docs/02-guides/03-using-generated-client.md.
  • Added tests/client_generators/dependencies/test_http_client_protocol.py: annotated assignments of httpx.Client/httpx.AsyncClient to every shipped protocol, which ty checks during hatch run lint. Verified that it fails against the old protocols.

The remote-schema HttpClient in schema.py is out of scope.

Verification

Generated async, sync, async+otel and sync+otel clients from a minimal schema and checked them with mypy 2.4.1 and pyright 1.1.414:

before after
mypy --check-untyped-defs (as in #463) errors in all variants clean in all variants
httpx.Client, httpx.AsyncClient, requests.Session passed as http_client rejected by mypy and pyright accepted

The remaining mypy --strict and pyright findings in the async websockets block (untyped ws_connect fallback, Data/Origin used as types) were already present in 0.18.0 and are left for a follow-up.

hatch run lint passes, and hatch test -a: 1052 passed on Python 3.10–3.14.

Fixes #463

- HttpClient protocols now take request arguments as keyword-only and
  drop **kwargs, so httpx.Client, httpx.AsyncClient and requests.Session
  satisfy them structurally. Base clients only call post() with keywords.
- Restore mypy-compatible `# type: ignore[...]` comments on the optional
  websockets and opentelemetry fallbacks (ty honours them as well).
- Add a ty-checked regression test assigning httpx clients to every
  shipped HttpClient protocol.
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4865198c-8f49-4790-b424-343bc0a409a0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@DamianCzajkowski
DamianCzajkowski merged commit 91fae27 into main Nov 2, 2026
6 checks passed
@DamianCzajkowski
DamianCzajkowski deleted the fix/http-client-protocol branch November 2, 2026 19:31
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.

Generated async client in 0.19.0 is not compatible with mypy

1 participant