Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing: Tighten type annotation for serialized user groups.
Zixuan James Lifc3de0ba41b6
diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.pyindex d4ee6a3a44b..f4b890c94a0 100644--- a/zerver/lib/user_groups.py+++ b/zerver/lib/user_groups.py@@ -1,4 +1,4 @@-from typing import Any, Dict, List, Sequence+from typing import Dict, List, Sequence, TypedDictfrom django.db import transactionfrom django.db.models import QuerySet@@ -9,6 +9,15 @@ from zerver.lib.exceptions import JsonableErrorfrom zerver.models import GroupGroupMembership, Realm, UserGroup, UserGroupMembership, UserProfile+class UserGroupDict(TypedDict):+ id: int+ name: str+ description: str+ members: List[int]+ direct_subgroup_ids: List[int]+ is_system_group: bool++def access_user_group_by_id(user_group_id: int, user_profile: UserProfile, *, for_read: bool = False) -> UserGroup:@@ -48,14 +57,14 @@ def access_user_groups_as_potential_subgroups(return list(user_groups)-def user_groups_in_realm_serialized(realm: Realm) -> List[Dict[str, Any]]:+def user_groups_in_realm_serialized(realm: Realm) -> List[UserGroupDict]:"""This function is used in do_events_register code path so this codeshould be performant. We need to do 2 database queries becauseDjango's ORM doesn't properly support the left join betweenUserGroup and UserGroupMembership that we need."""realm_groups = UserGroup.objects.filter(realm=realm)- group_dicts: Dict[str, Any] = {}+ group_dicts: Dict[int, UserGroupDict] = {}for user_group in realm_groups:group_dicts[user_group.id] = dict(id=user_group.id,