Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReturnDict annotations incorrect #217

Closed
09F911029D74E35BD84156C5635688C0 opened this issue May 5, 2022 · 3 comments · Fixed by #452
Closed

ReturnDict annotations incorrect #217

09F911029D74E35BD84156C5635688C0 opened this issue May 5, 2022 · 3 comments · Fixed by #452
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@09F911029D74E35BD84156C5635688C0

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-stubs version: 1.5.0
  • django-rest-framework version: 3.13.1
@09F911029D74E35BD84156C5635688C0 09F911029D74E35BD84156C5635688C0 added the bug Something isn't working label May 5, 2022
@tylerlaprade
Copy link

Bump - I am having trouble with the same issue.

@moosbruggerj
Copy link
Contributor

ReturnList has the same error.

I can provide a Pull request, if desired.

@intgr intgr added the good first issue Good for newcomers label Jul 24, 2023
@intgr
Copy link
Contributor

intgr commented Jul 24, 2023

Indeed, serializer= should be keyword-only argument. Pull requests welcome!

Also, instead of using *args, **kwargs , the remaining arguments should be copied and filled in from the base class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

4 participants