Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
users: Avoid unchecked cast.
Anders Kaseorg1e4fc8f2bf03
diff --git a/zerver/lib/types.py b/zerver/lib/types.pyindex bbc38efa703..fe33e4cd750 100644--- a/zerver/lib/types.py+++ b/zerver/lib/types.py@@ -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: intdiff --git a/zerver/lib/users.py b/zerver/lib/users.pyindex 9c5285f2c74..5f2a2ad3366 100644--- a/zerver/lib/users.py+++ b/zerver/lib/users.py@@ -1,7 +1,7 @@import reimport unicodedatafrom collections import defaultdict-from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast+from typing import Any, Dict, List, Optional, Sequence, Tuple, Unionfrom django.conf import settingsfrom 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")diff --git a/zerver/models.py b/zerver/models.pyindex ef08bc24f3c..73b844e9e5e 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -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 todiff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex 58df1043858..c45c949eed6 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -876,7 +876,7 @@ class UserProfileTest(ZulipTestCase):bot = self.example_user("default_bot")# Invalid user ID- invalid_uid: Any = 1000+ invalid_uid: object = 1000with 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}"):