From c37616ae5c1f4e0725a6312a6c982577fee26cc0 Mon Sep 17 00:00:00 2001 From: Oxan van Leeuwen Date: Mon, 25 Dec 2023 16:51:25 +0100 Subject: [PATCH] Document behaviour with type checkers (fixes #91) --- README.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.rst b/README.rst index c169fe9..c6cf7b8 100644 --- a/README.rst +++ b/README.rst @@ -593,3 +593,18 @@ module that contains the extension. .. _`drf-spectacular`: https://github.com/tfranzel/drf-spectacular .. _`extension`: https://github.com/tfranzel/drf-spectacular/blob/master/drf_spectacular/contrib/rest_framework_dataclasses.py + +Typing +------ +When using a type checker such as mypy, please ensure that the ``djangorestframework-stubs`` package is installed. The +type hints for this library depend on the type hints for DRF being available to validate successfully, and might +otherwise generate some seemingly bizarre mypy errors. + +The ``DataclassSerializer`` class is generic, and must be parameterized with the dataclass type to have correct types on +its properties and methods: + +.. code:: Python + + class PersonSerializer(DataclassSerializer[Person]): + class Meta: + dataclass = Person