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

Field.to_representation() should accept None #510

Open
Kangaroux opened this issue Nov 16, 2023 · 2 comments · May be fixed by #511
Open

Field.to_representation() should accept None #510

Kangaroux opened this issue Nov 16, 2023 · 2 comments · May be fixed by #511
Labels
bug Something isn't working

Comments

@Kangaroux
Copy link

Bug report

What's wrong

The type stubs do not allow to_representation to be given None, even though this is valid.

from rest_framework import serializers
serializers.DateField(allow_null=True).to_representation(None)

mypy error:

Argument 1 to "to_representation" of "Field" has incompatible type "None"; expected "date"  [arg-type]

How is that should be

None should be a supported value type for serializers.

System information

  • OS: PopOS 22.04
  • python version: 3.11.4
  • django version: 4.2.7
  • mypy version: 1.6.1
  • django-stubs version: 4.2.6
@Kangaroux Kangaroux added the bug Something isn't working label Nov 16, 2023
@intgr
Copy link
Contributor

intgr commented Nov 17, 2023

Agreed. Are you interested in opening a PR?

@Kangaroux
Copy link
Author

Agreed. Are you interested in opening a PR?

Yes, I created one #511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants