fix(web): type-checker-transparent request-binding markers (v26.06.07)#33
Merged
Merged
Conversation
…p v26.06.07 PathVar/QueryParam/Body/Header/Cookie/File/Valid were Generic[T] classes, so mypy --strict saw `order_id: PathVar[str]` as a PathVar[str] object, not str — user controllers written as documented could not pass strict typing without cast/# type: ignore. They are now Annotated[T, sentinel] aliases (mypy sees PathVar[str] as str, Valid[Body[Order]] as Order); the binder recovers the source from annotation metadata via the new pyfly.web.params.inspect_binding. Runtime binding semantics unchanged. Removed the now-redundant cast()/ignore workarounds in idp/web.py and transactional/rest/controllers.py. Updated tests/web/test_params.py + test_file_upload_types.py to the new contract. Gates: mypy --strict (607 files) clean, ruff clean, full suite 3623 passed.
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.
Summary
The web request-binding markers in
pyfly.web.params(PathVar,QueryParam,Body,Header,Cookie,File,Valid) were plainGeneric[T]classes.mypy --stricttherefore saw a handler parameterorder_id: PathVar[str]as aPathVar[str]object rather thanstr, so user controllers written exactly as the docs/skills show could not pass strict type-checking without# type: ignore/cast. (The framework's ownidp/web.pyandtransactional/rest/controllers.pyhad accumulated those workarounds; theorder_servicesample exhibits the errors but isn't type-checked.)Fix
Redefine the markers as
Annotated[T, <sentinel>]aliases:PathVar[str]asstrandValid[Body[Order]]asOrder— handler bodies passmypy --strictwith no escape hatches.pyfly.web.params.inspect_binding(hint) -> (binding, inner_type, validate), used by both the StarletteParameterResolver(shared with the FastAPI adapter) and the OpenAPI metadata extractor.Valid[...]validation with structured 422s, the flattenedValid[Body[T]]form, and theValid[Model]→ validated-body shorthand all behave identically.Removed the now-redundant
cast(...)/# type: ignoreworkarounds inidp/web.pyandtransactional/rest/controllers.py— these now serve as in-tree regression guards (reverting the markers would re-breakmypy src/pyfly).Tests
tests/web/test_params.pyto lock in the new contract viainspect_binding(all binding kinds +Validwrapping/standalone + nested flattening + the mypy-transparent underlying type).tests/web/test_file_upload_types.pyto the new representation.binding_type is PathVar,TestClientround-trips) unchanged and passing.Gates
mypy --strict(607 files) ✓ ·ruff✓ · full suite 3623 passed, 1 skipped.Bumps
v26.06.06 → v26.06.07(pyproject /__init__/ README), CHANGELOG entry,uv.locksynced.