Add type annotations to eliminate downstream stubs - #2
Merged
Conversation
Annotate class-level attributes and return types on APIView, GenericAPIView, and ViewSetMixin so that mypy can resolve them from the source directly, removing the need for external .pyi stubs.
Contributor
Author
|
@hoaxnerd Ready for review when you get a chance. |
_make_detail_endpoint, _make_body_detail_endpoint, and _make_action_endpoint all received pk_type but hardcoded int in the function annotations. This caused viewsets with non-integer PKs (str, UUID, etc.) to generate incorrect FastAPI endpoint signatures.
hoaxnerd
approved these changes
Mar 9, 2026
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
request,kwargsonAPIViewGenericAPIViewattributes (queryset,serializer_class,pagination_class,filter_backends,_paginator,_adapter) with concrete types (ORMAdapter,BasePagination,BaseFilterBackend) instead of bare assignmentslookup_field_typetoGenericAPIViewaction_mapdeclaration and typeserializer_classparam onViewSetMixinadapter,get_session,get_serializer_context,get_paginated_responseMotivation
Downstream projects (e.g.
aligned) maintain custom.pyistubs because fastrest's source doesn't expose enough type information despite shippingpy.typed. These annotations make the stubs unnecessary.Test plan
pytest tests/ -v— 410 tests passpython -c "import fastrest"— no import errorsmypy_path, ran mypy — passes (no new errors)