mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-21 19:32:16 +08:00
Allow Views to return the more generic HttpResponseBase instead of HttpResponse, to allow returning StreamingHttpResponse (#607)
* Add type hints for the postgres CursorDebugWrapper, expand the BaseCursorDebugWrapper. * Fix how Optinal gets applied. * Fix optional handling further. * Adjust postgres debugcursorwrapper to look more like the implementation. * Apply review feedback. * Use the more generic HttpResponseBase when appriopriate. * Fix failing test and add new test. * Remove the other test again, it was the wrong location. Add new tests in the correct location. Co-authored-by: LanDinh <coding+sourcetree@khaleesi.ninja>
This commit is contained in:
@@ -11,10 +11,10 @@
|
||||
from django.views.generic.base import View
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http.response import HttpResponse
|
||||
from django.http.response import HttpResponseBase
|
||||
from django.http.request import HttpRequest
|
||||
class TestView(View):
|
||||
@method_decorator(login_required)
|
||||
def dispatch(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
|
||||
def dispatch(self, request: HttpRequest, *args, **kwargs) -> HttpResponseBase:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
reveal_type(dispatch) # N: Revealed type is 'def (self: main.TestView, request: django.http.request.HttpRequest, *args: Any, **kwargs: Any) -> django.http.response.HttpResponse'
|
||||
reveal_type(dispatch) # N: Revealed type is 'def (self: main.TestView, request: django.http.request.HttpRequest, *args: Any, **kwargs: Any) -> django.http.response.HttpResponseBase'
|
||||
|
||||
@@ -10,3 +10,21 @@
|
||||
"""Ensure that form can have type AuthenticationForm."""
|
||||
form.get_user()
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
- case: dispatch_http_response
|
||||
main: |
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic.base import View
|
||||
|
||||
class MyView(View):
|
||||
def dispatch(self, request, *args, **kwargs) -> HttpResponse:
|
||||
response: HttpResponse
|
||||
return response
|
||||
- case: dispatch_streaming_http_response
|
||||
main: |
|
||||
from django.http import StreamingHttpResponse
|
||||
from django.views.generic.base import View
|
||||
|
||||
class MyView(View):
|
||||
def dispatch(self, request, *args, **kwargs) -> StreamingHttpResponse:
|
||||
response: StreamingHttpResponse
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user