Skip to content

Wrong return type for Field.get_attribute() #829

@Feuermurmel

Description

@Feuermurmel

Bug report

What's wrong

The return type of Field.get_attribute() is declared as _RP, but I think it should be _VT.

How is that should be

Looking at the implementation of Serializer.to_representation(), the value returned by Field.get_attribute() is passed to Field.to_representation(), whose argument is declared to be _VT. Thus I think the declaration of Field.get_attribute() should be changed to:

def get_attribute(self, instance: _IN) -> _VT | None: ...

System information

  • OS: macOS 14.8
  • python version: Python 3.12.11
  • django version: 4.2.24
  • mypy version: 1.15.0
  • django-stubs version: 5.2.5

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