Skip to content

Improve GenericAPIView.serializer_class classvar type generics #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2024

Conversation

jheld
Copy link
Contributor

@jheld jheld commented Sep 27, 2024

I have made things!

The type for the attribute does not match what the get_serializer_class function returns.

Thus, modifying it to match so that the truthy type of it is type[BaseSerializer[_MT_co]]

Unfortunately this doesn't solve the issue of projects programmatically returning different serializers in get_serializer_class such that one option would be: return self.serializer_class such that it would be technically incompatible with the typing. But that seems outside the scope of this change and there are other ways to accomplish it (e.g. holding known serializer classes in a dict on the class as an attribute).

Related issues

The type for the attribute does not match what the `get_serializer_class` function returns.

Thus, modifying it to match so it is `type[BaseSerializer[_MT_co]]`

Unfortunately this doesn't solve the issue of projects programmatically returning different serializers in `get_serializer_class` such that one option would be: `return self.serializer_class` such that it would be technically incompatible with the typing. But that seems outside the scope of this change and there are other ways to accomplish it (e.g. holding known serializer classes in a `dict` on the class as an attribute).
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the change is correct.

Copy link
Contributor

@intgr intgr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@intgr intgr changed the title Update generics.pyi serializer_class [_MT_co] Improve GenericAPIView.serializer_class classvar type generics Sep 28, 2024
@intgr intgr merged commit 496b117 into typeddjango:master Sep 28, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

GenericAPIView serializer_class type should use _MT_co
3 participants