opentelemetry-instrumentation-httpx: support strict typing#4833
Open
henry3260 wants to merge 2 commits into
Open
opentelemetry-instrumentation-httpx: support strict typing#4833henry3260 wants to merge 2 commits into
henry3260 wants to merge 2 commits into
Conversation
henry3260
force-pushed
the
httpx-strict-typing
branch
from
July 18, 2026 01:24
ed0be17 to
2a97a2c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
opentelemetry-instrumentation-httpxto the pyright strict typecheckenvironment (
tox.initypecheck deps + pyrightincludeinpyproject.toml)and fix the typing across the instrumentation. Follow-up to the review
discussion in #4730.
Notable changes, none of which are intended to change runtime behavior:
isinstancedispatch in_extract_response(checktuplefirst) so pyright narrowing works soundly in both branches; this removes the
previously flagged unnecessary
typing.castcalls.handle_request/handle_async_requestmethods asreturning
httpx.Responseto be compatible with thehttpx.BaseTransportoverride; the httpx < 0.20 tuple form is still handled at runtime.
instrument_clientviaTypeIsguards(pyright does not narrow callable unions in the negative direction, so a
pair of positive guards is used).
dict[str, AttributeValue]and make thewrapper histogram/hook parameters optional to match call sites.
RequestInfo/ResponseInfourlandextensionsfield annotationsto match the raw values the transport layer actually passes.
Remaining suppressions: two
typing.castcalls at the transport returns(control-flow invariant pyright cannot see, documented inline) and two
targeted
pyright: ignorecomments for untypedwraptand the deprecatedMetricInstrumentsname required by the old semconv mode — both followexisting precedent in already-typechecked packages.
Package tests remain excluded from typecheck for now, consistent with the
other packages in the include list.
Fixes #4818
Type of change
How Has This Been Tested?
tox -e typecheck— 0 errors for the packagetox -e lint-instrumentation-httpx— 10.00/10tox -e py312-test-instrumentation-httpx-{0,1,2,3}-wrapt2,py312-test-instrumentation-httpx-1-wrapt1, andpy310-test-instrumentation-httpx-1-wrapt2— all pass; the-0factor(httpx 0.18) exercises the legacy tuple code path touched by the
_extract_responserestructuringDoes This PR Require a Core Repo Change?
Checklist: