Skip to content

Commit 7573e2e

Browse files
authored
Update admin.sites._ViewType bound to allow StreamingHttpResponse (#2256)
* Update `admin.sites._ViewType` bound to allow `StreamingHttpResponse` From the [Django documentation](https://docs.djangoproject.com/en/5.0/ref/request-response/#streaminghttpresponse-objects): > The `StreamingHttpResponse` is not a subclass of `HttpResponse` ... Because of this, creating an admin view that returned a `StreamingHttpResponse` was causing the following Mypy error: ``` testing/admin.py:14: error: Value of type variable "_ViewType" of "admin_view" of "AdminSite" cannot be "Callable[[HttpRequest], StreamingHttpResponse]" [type-var] ``` This updates the admin `_ViewType` type-var bound to allow a Callable that can return a union of `HttpResponse | StreamingHttpResponse`. After this update to the stubs file, the Mypy error is no longer reproducible. * Use `HttpResponseBase` common parent instead
1 parent 6442aee commit 7573e2e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

django-stubs/contrib/admin/sites.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from django.core.checks import CheckMessage
1010
from django.db.models.base import Model
1111
from django.db.models.query import QuerySet
1212
from django.http.request import HttpRequest
13-
from django.http.response import HttpResponse
13+
from django.http.response import HttpResponse, HttpResponseBase
1414
from django.template.response import TemplateResponse
1515
from django.urls import URLPattern, URLResolver
1616
from django.utils.functional import LazyObject, _StrOrPromise
@@ -25,7 +25,7 @@ else:
2525

2626
all_sites: MutableSet[AdminSite]
2727

28-
_ViewType = TypeVar("_ViewType", bound=Callable[..., HttpResponse])
28+
_ViewType = TypeVar("_ViewType", bound=Callable[..., HttpResponseBase])
2929
_ModelT = TypeVar("_ModelT", bound=Model)
3030
_ActionCallback: TypeAlias = Callable[[ModelAdmin, HttpRequest, QuerySet], TemplateResponse | None]
3131

0 commit comments

Comments
 (0)