mirror of https://github.com/zulip/zulip.git
validators: Improve mypy type annotations.
The main thing here is writing check_string_fixed_length and check_capped_string as returning a Validator, but we also fix issues around passing default=None.
This commit is contained in:
parent
51517fa188
commit
b1ad7593ba
|
@ -23,7 +23,7 @@ def REQ(whence: Optional[str] = None,
|
|||
*,
|
||||
type: Type[ResultT] = Type[None],
|
||||
converter: Optional[Callable[[str], ResultT]] = None,
|
||||
default: Union[_NotSpecified, ResultT] = NotSpecified,
|
||||
default: Union[_NotSpecified, ResultT, None] = Optional[NotSpecified],
|
||||
validator: Optional[Validator] = None,
|
||||
str_validator: Optional[Validator] = None,
|
||||
argument_type: Optional[str] = None) -> ResultT: ...
|
||||
|
|
|
@ -55,7 +55,7 @@ def check_required_string(var_name: str, val: object) -> Optional[str]:
|
|||
def check_short_string(var_name: str, val: object) -> Optional[str]:
|
||||
return check_capped_string(50)(var_name, val)
|
||||
|
||||
def check_capped_string(max_length: int) -> Callable[[str, object], Optional[str]]:
|
||||
def check_capped_string(max_length: int) -> Validator:
|
||||
def validator(var_name: str, val: object) -> Optional[str]:
|
||||
if not isinstance(val, str):
|
||||
return _('%s is not a string') % (var_name,)
|
||||
|
@ -65,7 +65,7 @@ def check_capped_string(max_length: int) -> Callable[[str, object], Optional[str
|
|||
return None
|
||||
return validator
|
||||
|
||||
def check_string_fixed_length(length: int) -> Callable[[str, object], Optional[str]]:
|
||||
def check_string_fixed_length(length: int) -> Validator:
|
||||
def validator(var_name: str, val: object) -> Optional[str]:
|
||||
if not isinstance(val, str):
|
||||
return _('%s is not a string') % (var_name,)
|
||||
|
|
Loading…
Reference in New Issue