Skip to content

Add type annotations to eliminate downstream stubs - #2

Merged
hoaxnerd merged 2 commits into
hoaxnerd:mainfrom
corrin:add-type-annotations
Mar 9, 2026
Merged

Add type annotations to eliminate downstream stubs#2
hoaxnerd merged 2 commits into
hoaxnerd:mainfrom
corrin:add-type-annotations

Conversation

@corrin

@corrin corrin commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add class-level type declarations for request, kwargs on APIView
  • Annotate GenericAPIView attributes (queryset, serializer_class, pagination_class, filter_backends, _paginator, _adapter) with concrete types (ORMAdapter, BasePagination, BaseFilterBackend) instead of bare assignments
  • Add missing lookup_field_type to GenericAPIView
  • Add action_map declaration and type serializer_class param on ViewSetMixin
  • Add return types on adapter, get_session, get_serializer_context, get_paginated_response

Motivation

Downstream projects (e.g. aligned) maintain custom .pyi stubs because fastrest's source doesn't expose enough type information despite shipping py.typed. These annotations make the stubs unnecessary.

Test plan

  • pytest tests/ -v — 410 tests pass
  • python -c "import fastrest" — no import errors
  • Installed into downstream project, deleted stubs, removed mypy_path, ran mypy — passes (no new errors)

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.
@corrin

corrin commented Mar 8, 2026

Copy link
Copy Markdown
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
hoaxnerd merged commit 3b18ae8 into hoaxnerd:main Mar 9, 2026
5 checks passed
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.

2 participants