Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
rest: Strengthen default_never_cache_responses type.
Anders Kaseorgb655029cedc5
diff --git a/zerver/lib/rest.py b/zerver/lib/rest.pyindex 01095d21bfe..f54cd2ce67d 100644--- a/zerver/lib/rest.py+++ b/zerver/lib/rest.py@@ -1,5 +1,5 @@from functools import wraps-from typing import Any, Callable, Dict+from typing import Any, Dict, castfrom django.conf import settingsfrom django.http import HttpRequest, HttpResponse, HttpResponseRedirect@@ -8,33 +8,32 @@ from django.utils.module_loading import import_stringfrom django.views.decorators.csrf import csrf_exempt, csrf_protectfrom zerver.decorator import (- ReturnT,authenticated_json_view,authenticated_rest_api_view,authenticated_uploads_api_view,process_as_post,)from zerver.lib.response import json_method_not_allowed, json_unauthorized+from zerver.lib.types import ViewFuncTMETHODS = ('GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH')FLAGS = ('override_api_url_scheme')-def default_never_cache_responses(- view_func: Callable[..., HttpResponse]) -> Callable[..., HttpResponse]:+def default_never_cache_responses(view_func: ViewFuncT) -> ViewFuncT:"""Patched version of the standard Django never_cache_responsesdecorator that adds headers to a response so that it will never becached, unless the view code has already set a Cache-Controlheader."""@wraps(view_func)- def _wrapped_view_func(request: HttpRequest, *args: Any, **kwargs: Any) -> ReturnT:+ def _wrapped_view_func(request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse:response = view_func(request, *args, **kwargs)if response.has_header("Cache-Control"):return responseadd_never_cache_headers(response)return response- return _wrapped_view_func+ return cast(ViewFuncT, _wrapped_view_func) # https://github.com/python/mypy/issues/1927@default_never_cache_responses@csrf_exempt