You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The handler layer currently uses requests.PreparedRequest as its internal request representation. This ties the core business logic to the requests library unnecessarily, since handlers immediately decompose it into primitive types (str, bytes, Mapping[str, str]) before passing them to validators.
Summary
The handler layer currently uses
requests.PreparedRequestas its internal request representation. This ties the core business logic to therequestslibrary unnecessarily, since handlers immediately decompose it into primitive types (str,bytes,Mapping[str, str]) before passing them to validators.Problem
respxadapter must converthttpx.Request→PreparedRequest, which caused type-checking conflicts between mypy, pyrefly, and ruff (see Add respx support for mocking httpx requests #2973)PreparedRequest— it extracts primitives directly from Flask/werkzeug's request objectPreparedRequest.bodyisbytes | str | None, requiring a_body_bytes()normalizer in two separate filesPreparedRequest.methodisstr | None, requiringor ""guards in every handlerProposed Solution
Replace
PreparedRequestwith a simple, library-agnostic dataclass:Each adapter converts to this at the boundary:
responsesadapter:PreparedRequest→MockRequestrespxadapter:httpx.Request→MockRequestflask.request→MockRequestBenefits
requeststypes in the handler/validator layer# type: ignore,# noqa) in the respx adapter_body_bytes()helper (body normalization happens once at conversion)or ""guards for method (normalization happens once at conversion)