mirror of https://github.com/zulip/zulip.git
users: Avoid unchecked cast.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
086a3ef18b
commit
1e4fc8f2bf
|
@ -10,7 +10,7 @@ ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse])
|
|||
ResultT = TypeVar("ResultT")
|
||||
Validator = Callable[[str, object], ResultT]
|
||||
ExtendedValidator = Callable[[str, str, object], str]
|
||||
RealmUserValidator = Callable[[int, List[int], bool], List[int]]
|
||||
RealmUserValidator = Callable[[int, object, bool], List[int]]
|
||||
|
||||
class ProfileDataElementBase(TypedDict):
|
||||
id: int
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
import unicodedata
|
||||
from collections import defaultdict
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
|
@ -269,7 +269,7 @@ def validate_user_custom_profile_field(realm_id: int, field: CustomProfileField,
|
|||
return choice_field_validator(var_name, field_data, value)
|
||||
elif field_type == CustomProfileField.USER:
|
||||
user_field_validator = CustomProfileField.USER_FIELD_VALIDATORS[field_type]
|
||||
return user_field_validator(realm_id, cast(List[int], value), False)
|
||||
return user_field_validator(realm_id, value, False)
|
||||
else:
|
||||
raise AssertionError("Invalid field type")
|
||||
|
||||
|
|
|
@ -2754,9 +2754,9 @@ class UserHotspot(models.Model):
|
|||
class Meta:
|
||||
unique_together = ("user", "hotspot")
|
||||
|
||||
def check_valid_user_ids(realm_id: int, user_ids: List[int],
|
||||
def check_valid_user_ids(realm_id: int, val: object,
|
||||
allow_deactivated: bool=False) -> List[int]:
|
||||
check_list(check_int)("User IDs", user_ids)
|
||||
user_ids = check_list(check_int)("User IDs", val)
|
||||
realm = Realm.objects.get(id=realm_id)
|
||||
for user_id in user_ids:
|
||||
# TODO: Structurally, we should be doing a bulk fetch query to
|
||||
|
|
|
@ -876,7 +876,7 @@ class UserProfileTest(ZulipTestCase):
|
|||
bot = self.example_user("default_bot")
|
||||
|
||||
# Invalid user ID
|
||||
invalid_uid: Any = 1000
|
||||
invalid_uid: object = 1000
|
||||
with self.assertRaisesRegex(ValidationError, r"User IDs is not a list"):
|
||||
check_valid_user_ids(realm.id, invalid_uid)
|
||||
with self.assertRaisesRegex(ValidationError, rf"Invalid user ID: {invalid_uid}"):
|
||||
|
|
Loading…
Reference in New Issue