mirror of https://github.com/zulip/zulip.git
mypy: Annotate zerver/lib/request.py.
This commit is contained in:
parent
612e3766ce
commit
2541b29bdc
|
@ -10,15 +10,19 @@ from django.utils.translation import ugettext as _
|
|||
|
||||
from zerver.lib.exceptions import JsonableError, ErrorCode
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
class RequestVariableMissingError(JsonableError):
|
||||
code = ErrorCode.REQUEST_VARIABLE_MISSING
|
||||
data_fields = ['var_name']
|
||||
|
||||
def __init__(self, var_name):
|
||||
# type: (str) -> None
|
||||
self.var_name = var_name # type: str
|
||||
|
||||
@staticmethod
|
||||
def msg_format():
|
||||
# type: () -> str
|
||||
return _("Missing '{var_name}' argument")
|
||||
|
||||
class RequestVariableConversionError(JsonableError):
|
||||
|
@ -26,11 +30,13 @@ class RequestVariableConversionError(JsonableError):
|
|||
data_fields = ['var_name', 'bad_value']
|
||||
|
||||
def __init__(self, var_name, bad_value):
|
||||
# type: (str, Any) -> None
|
||||
self.var_name = var_name # type: str
|
||||
self.bad_value = bad_value
|
||||
|
||||
@staticmethod
|
||||
def msg_format():
|
||||
# type: () -> str
|
||||
return _("Bad value for '{var_name}': {bad_value}")
|
||||
|
||||
# Used in conjunction with @has_request_variables, below
|
||||
|
@ -44,6 +50,7 @@ class REQ(object):
|
|||
|
||||
def __init__(self, whence=None, converter=None, default=NotSpecified,
|
||||
validator=None, argument_type=None):
|
||||
# type: (str, Callable[Any, Any], Any, Callable[Any, Any], str) -> None
|
||||
"""whence: the name of the request variable that should be used
|
||||
for this parameter. Defaults to a request variable of the
|
||||
same name as the parameter.
|
||||
|
@ -91,6 +98,7 @@ class REQ(object):
|
|||
# expected to call json_error or json_success, as it uses json_error
|
||||
# internally when it encounters an error
|
||||
def has_request_variables(view_func):
|
||||
# type: (Callable[[HttpRequest, *Any, **Any], HttpResponse]) -> Callable[[HttpRequest, *Any, **Any], HttpResponse]
|
||||
num_params = view_func.__code__.co_argcount
|
||||
if view_func.__defaults__ is None:
|
||||
num_default_params = 0
|
||||
|
@ -112,6 +120,7 @@ def has_request_variables(view_func):
|
|||
|
||||
@wraps(view_func)
|
||||
def _wrapped_view_func(request, *args, **kwargs):
|
||||
# type: (HttpRequest, *Any, **Any) -> HttpResponse
|
||||
for param in post_params:
|
||||
if param.func_var_name in kwargs:
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue