Skip to content

Field.to_representation() should accept None #510

Open
@Kangaroux

Description

@Kangaroux

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions