return type for django.views.static is less specific than expected.
What's wrong
The current definition for django.views.static.serve specifies the return type as HttpResponseBase. Prior to that. it was specified as FileResponse.
How is that should be
As far as I'm aware, the return type for django.views.static.serve is actually:
Union[HttpResponse, HttpResponseNotModified, FileResponse]
Specifically:
-
HttpResponseis viadirectory_index -
HttpResponseNotModifiedis forIf-Modified-Since -
FileResponseis the file sending itself.
System information
-
djangoversion: Any, I think. The last version to offer another return type was1.10.6before the redirect functionality was removed. -
mypyversion: 0.960 -
django-stubsversion: master
Is there any practical difference for you between HttpResponseBase and HttpResponse | FileResponse? It is not a single place where HttpResponse | FileResponse are widened to HttpResponseBase, this makes subclassing easier plus is more readable in general. Could you show a use case where it changes type checking process (adds or removes errors or affects implementation)?
HttpResponseNotModified is a subclass of HttpResponse AFAIR, so doesn't need to be included in union.