validator: Remove unused check_tuple function.

Tuples cannot be deserialized from JSON.

While we do use these validators for other things, like event
dictionaries, we have migrated the API away from using those.  The
last use was removed in 4f3d5f2d87

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-08-13 18:39:47 -07:00 committed by Tim Abbott
parent f3e5ed57ae
commit 404ef284bb
2 changed files with 0 additions and 39 deletions

View File

@ -217,29 +217,6 @@ def check_list(
return f
def check_tuple(sub_validators: List[Validator[ResultT]]) -> Validator[Tuple[Any, ...]]:
def f(var_name: str, val: object) -> Tuple[Any, ...]:
if not isinstance(val, tuple):
raise ValidationError(_("{var_name} is not a tuple").format(var_name=var_name))
desired_len = len(sub_validators)
if desired_len != len(val):
raise ValidationError(
_("{var_name} should have exactly {desired_len} items").format(
var_name=var_name,
desired_len=desired_len,
)
)
for i, sub_validator in enumerate(sub_validators):
vname = f"{var_name}[{i}]"
sub_validator(vname, val[i])
return val
return f
# https://zulip.readthedocs.io/en/latest/testing/mypy.html#using-overload-to-accurately-describe-variations
@overload
def check_dict(

View File

@ -77,7 +77,6 @@ from zerver.lib.validator import (
check_string_in,
check_string_or_int,
check_string_or_int_list,
check_tuple,
check_union,
check_url,
equals,
@ -817,21 +816,6 @@ class ValidatorTestCase(ZulipTestCase):
with self.assertRaisesRegex(ValidationError, r"color is not a string"):
check_color("color", z)
def test_check_tuple(self) -> None:
x: Any = 999
with self.assertRaisesRegex(ValidationError, r"x is not a tuple"):
check_tuple([check_string])("x", x)
x = (5, 2)
with self.assertRaisesRegex(ValidationError, r"x\[0\] is not a string"):
check_tuple([check_string, check_string])("x", x)
x = (1, 2, 3)
with self.assertRaisesRegex(ValidationError, r"x should have exactly 2 items"):
check_tuple([check_int, check_int])("x", x)
check_tuple([check_string, check_int])("x", ("string", 42))
def test_check_list(self) -> None:
x: Any = 999
with self.assertRaisesRegex(ValidationError, r"x is not a list"):