mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
It was allowing us to get away with wrong types on a few functions: `check_send_typing_notification` and `send_notification_backend` can be (and are) called with a list of `int` as `notification_to`, not just a list of `str`. The problem it was working around already had a better solution using the dummy `type` argument. Use that. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
# This mypy stubs file ensures that mypy can correctly analyze REQ.
|
|
#
|
|
# Note that here REQ is claimed to be a function, with a return type to match
|
|
# that of the parameter of which it is the default value, allowing type
|
|
# checking. However, in request.py, REQ is a class to enable the decorator to
|
|
# scan the parameter list for REQ objects and patch the parameters as the true
|
|
# types.
|
|
|
|
from typing import Dict, Callable, List, TypeVar, Optional, Union, Type
|
|
from zerver.lib.types import ViewFuncT, Validator
|
|
from zerver.lib.exceptions import JsonableError as JsonableError
|
|
|
|
ResultT = TypeVar('ResultT')
|
|
|
|
class RequestConfusingParmsError(JsonableError): ...
|
|
class RequestVariableMissingError(JsonableError): ...
|
|
class RequestVariableConversionError(JsonableError): ...
|
|
|
|
class _NotSpecified: ...
|
|
NotSpecified = _NotSpecified()
|
|
|
|
def REQ(whence: Optional[str] = None,
|
|
*,
|
|
type: Type[ResultT] = Type[None],
|
|
converter: Optional[Callable[[str], ResultT]] = None,
|
|
default: Union[_NotSpecified, ResultT, None] = NotSpecified,
|
|
validator: Optional[Validator] = None,
|
|
str_validator: Optional[Validator] = None,
|
|
argument_type: Optional[str] = None,
|
|
intentionally_undocumented: bool=False,
|
|
documentation_pending: bool=False,
|
|
aliases: Optional[List[str]] = None) -> ResultT: ...
|
|
|
|
def has_request_variables(view_func: ViewFuncT) -> ViewFuncT: ...
|
|
arguments_map = ... # type: Dict[str, List[str]]
|