Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

typing: Add none-checks for Recipient objects.

Zixuan James Lie338ada66c67
diff --git a/zerver/lib/retention.py b/zerver/lib/retention.py
index a3304855e65..f673bf98374 100644
--- a/zerver/lib/retention.py
+++ b/zerver/lib/retention.py
@@ -420,6 +420,7 @@ def archive_stream_messages(
recipients = [stream.recipient for stream in streams]
message_count = 0
for recipient in recipients:
+ assert recipient is not None
message_count += archive_messages_by_recipient(
recipient,
retention_policy_dict[recipient.type_id],
diff --git a/zerver/tests/test_message_dict.py b/zerver/tests/test_message_dict.py
index 8989d88a25f..66ec605190e 100644
--- a/zerver/tests/test_message_dict.py
+++ b/zerver/tests/test_message_dict.py
@@ -450,6 +450,7 @@ class MessageHydrationTest(ZulipTestCase):
cordelia_recipient = cordelia.recipient
# Cause the display_recipient to get cached:
+ assert cordelia_recipient is not None
get_display_recipient(cordelia_recipient)
# Change cordelia's email:
diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py
index ee655716124..3c1c3b9d1ca 100644
--- a/zerver/tests/test_message_fetch.py
+++ b/zerver/tests/test_message_fetch.py
@@ -1378,6 +1378,9 @@ class GetOldMessagesTest(ZulipTestCase):
query_ids: Dict[str, Union[int, str]] = {}
scotland_stream = get_stream("Scotland", hamlet_user.realm)
+ assert scotland_stream.recipient_id is not None
+ assert hamlet_user.recipient_id is not None
+ assert othello_user.recipient_id is not None
query_ids["scotland_recipient"] = scotland_stream.recipient_id
query_ids["hamlet_id"] = hamlet_user.id
query_ids["othello_id"] = othello_user.id
diff --git a/zerver/tests/test_muting_topics.py b/zerver/tests/test_muting_topics.py
index 1e360bd31c4..2a407fa069d 100644
--- a/zerver/tests/test_muting_topics.py
+++ b/zerver/tests/test_muting_topics.py
@@ -118,6 +118,7 @@ class MutedTopicsTests(ZulipTestCase):
# trying to mute the topic. To do this, we patch the
# topic_is_muted function to always return False when trying
# to mute a topic that is already muted.
+ assert stream.recipient is not None
add_topic_mute(
user_profile=user,
stream_id=stream.id,
diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.py
index c09e8c60d39..3280e09b896 100644
--- a/zerver/views/message_fetch.py
+++ b/zerver/views/message_fetch.py
@@ -298,6 +298,7 @@ class NarrowBuilder:
return query.where(maybe_negate(cond))
recipient = stream.recipient
+ assert recipient is not None
cond = column("recipient_id", Integer) == recipient.id
return query.where(maybe_negate(cond))
diff --git a/zerver/views/message_flags.py b/zerver/views/message_flags.py
index 8670baca1e3..ebb76b222b6 100644
--- a/zerver/views/message_flags.py
+++ b/zerver/views/message_flags.py
@@ -82,6 +82,7 @@ def mark_topic_as_read(
topic_name: str = REQ(),
) -> HttpResponse:
stream, sub = access_stream_by_id(user_profile, stream_id)
+ assert stream.recipient_id is not None
if topic_name:
topic_exists = user_message_exists_for_topic(