djangorestframework-stubs
djangorestframework-stubs copied to clipboard
error: "Response" has no attribute "json"
Bug report
What's wrong
Given the snippet such as this
from rest_framework.response import Response
from rest_framework.test import APIClient
def test_response(api_client: APIClient) -> None:
response: Response = api_client.get('https://example.com/example.json')
assert response.json() == {}
and running mypy . on it, I receive error: "Response" has no attribute "json"
Running the test works fine.
The reason is that rest_framework-stubs/response.pyi declares Response to inherit from django.template.response.SimpleTemplateResponse and this class in turn does not declare the json field, it's the TemplateResponse that does.
This was already reported in django-stubs here: https://github.com/typeddjango/django-stubs/issues/962 I'm not that person.
How is that should be
Since the test works mypy shouldn't complain that the method Response.json() does not exist.
System information
- OS: Linux
pythonversion: 3.8.11djangoversion: 3.0.14mypyversion: 0.950django-stubsversion: 1.11.0