mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
These changes are in one commit, since the previous typing of check_url does not match the centralized strict definition (object/Any vs Text), actually already used elsewhere in validator.py, and also had a different API. check_url is updated here to match the API of the other check_* functions, ie. val is an object (not Text) & returns Optional[str]. It also now checks the value is text explicitly at run-time, which was only type-checked previously. Tests are updated accordingly.
31 lines
1.1 KiB
Python
31 lines
1.1 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 Any, Callable, Text, TypeVar, Optional, Union, Type
|
|
from zerver.lib.types import ViewFuncT, Validator
|
|
|
|
from zerver.lib.exceptions import JsonableError as JsonableError
|
|
|
|
ResultT = TypeVar('ResultT')
|
|
|
|
class RequestVariableMissingError(JsonableError): ...
|
|
class RequestVariableConversionError(JsonableError): ...
|
|
|
|
class _NotSpecified: ...
|
|
NotSpecified = _NotSpecified()
|
|
|
|
def REQ(whence: Optional[str] = None,
|
|
*,
|
|
type: Type[ResultT] = None,
|
|
converter: Optional[Callable[[str], ResultT]] = None,
|
|
default: Union[_NotSpecified, ResultT] = NotSpecified,
|
|
validator: Optional[Validator] = None,
|
|
argument_type: Optional[str] = None) -> ResultT: ...
|
|
|
|
def has_request_variables(view_func: ViewFuncT) -> ViewFuncT: ...
|