From 4f4d61cb59da26efebcbb703e104f5fc36be46f5 Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Wed, 10 Aug 2022 14:48:11 -0400 Subject: [PATCH] user_topics: Refactor the construction loop for UserTopicDict. This ensures type safety by not mutating the original queryset values, that django-stubs to type as a TypedDict without total=False. Signed-off-by: Zixuan James Li --- zerver/lib/user_topics.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/zerver/lib/user_topics.py b/zerver/lib/user_topics.py index 11723155f6..1b1f722ba0 100644 --- a/zerver/lib/user_topics.py +++ b/zerver/lib/user_topics.py @@ -43,11 +43,17 @@ def get_user_topics( result = [] for row in rows: - if not include_stream_name: - del row["stream__name"] + user_topic_dict: UserTopicDict = { + "stream_id": row["stream_id"], + "topic_name": row["topic_name"], + "visibility_policy": row["visibility_policy"], + "last_updated": datetime_to_timestamp(row["last_updated"]), + } - row["last_updated"] = datetime_to_timestamp(row["last_updated"]) - result.append(row) + if include_stream_name: + user_topic_dict["stream__name"] = row["stream__name"] + + result.append(user_topic_dict) return result