django-stubs icon indicating copy to clipboard operation
django-stubs copied to clipboard

regression in 5.2? cannot extract `rest_framework` `Response` from django test client

Open asottile-sentry opened this issue 5 months ago • 4 comments

Bug report

seems something in 5.2 caused this to break -- here's a minimal example:

from django.test import TestCase
from rest_framework.response import Response


class T(TestCase):
    def get_rf_resp(self, url: str) -> Response:
        resp = self.client.get(url)
        assert isinstance(resp, Response), resp
        return resp

What's wrong

$ mypy t3.py --warn-unreachable
t3.py:8: error: Subclass of "_MonkeyPatchedWSGIResponse" and "Response" cannot exist: would have incompatible method signatures  [unreachable]
t3.py:9: error: Statement is unreachable  [unreachable]
Found 2 errors in 1 file (checked 1 source file)

How is that should be

no errors

System information

  • OS:
  • python version: 3.13.1
  • django version: 5.2.0
  • mypy version: 1.15.0
  • django-stubs version: 5.2.0 (forked, but not relevant here)
  • django-stubs-ext version: 5.2.0

asottile-sentry avatar May 13 '25 17:05 asottile-sentry