typeddjango / djangorestframework-stubs

PEP-484 stubs for django-rest-framework
MIT License
439 stars 115 forks source link

Field.to_representation() should accept None #510

Open Kangaroux opened 10 months ago

Kangaroux commented 10 months ago

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

intgr commented 10 months ago

Agreed. Are you interested in opening a PR?

Kangaroux commented 10 months ago

Agreed. Are you interested in opening a PR?

Yes, I created one #511