djangorestframework-stubs
djangorestframework-stubs copied to clipboard
ReturnDict annotations incorrect
Bug report
What's wrong
The stubs say that ReturnDict has serializer as first argument, but actually it's a keyword only argument. First argument should be a Mapping. (or whatever parent OrderedDict takes).
from rest_framework.utils.serializer_helpers import ReturnDict
from rest_framework.serializers import Serializer
d = ReturnDict({"key": "val"}, serializer=Serializer())
produces:
test.py:5: error: "ReturnDict" gets multiple values for keyword argument "serializer" [misc]
test.py:5: error: Argument 1 to "ReturnDict" has incompatible type "Dict[str, str]"; expected "BaseSerializer[Any]" [arg-type]
How is that should be
It should not give an error. That's the usage in drf itself
https://github.com/encode/django-rest-framework/blob/3.13.1/rest_framework/utils/serializer_helpers.py#L16 https://github.com/encode/django-rest-framework/blob/3.13.1/rest_framework/serializers.py#L553
@property
def data(self):
ret = super().data
return ReturnDict(ret, serializer=self)
System information
django-stubsversion: 1.5.0django-rest-frameworkversion: 3.13.1