Skip to content
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

Improve type hints for UserSerializer #4429

Conversation

browniebroke
Copy link
Member

@browniebroke browniebroke commented Jun 29, 2023

Description

I recently came across the fact that djangorestframework-stubs supports using generics in model serializers, which has the effect of improving type hints: self.instance is known to be an instance of the model instead of Any.

It would be nice to show that feature in the only serializer that we include, the UserSerializer.

Checklist:

  • I've made sure that tests are updated accordingly (especially if adding or updating a template option)
  • I've updated the documentation or confirm that my change doesn't require any updates

Rationale

Improve discoverability of a nice feature, improve type checking, improve auto-completion.

@browniebroke browniebroke changed the title Improve type hints for UserSerializer Improve type hints for UserSerializer Jun 29, 2023
@browniebroke browniebroke force-pushed the better-type-hints-for-userserializer branch from e024a0c to 496e457 Compare July 10, 2023 08:40
@foarsitter
Copy link
Collaborator

It is good to know about this feature. Do you have some more background on this?

@browniebroke
Copy link
Member Author

I've stumbled upon that in a closed issue on the DRF-stubs and I'm intending to send a pull request to document these better in the upstream project. For now, I'm learning more about them in one of my projects.

@browniebroke
Copy link
Member Author

Unless there is any objections, I'm going to merge this in the next couple of days, it seems pretty safe AFAIK

@browniebroke browniebroke merged commit 67a7194 into cookiecutter:master Jul 11, 2023
11 checks passed
@browniebroke browniebroke deleted the better-type-hints-for-userserializer branch July 11, 2023 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants