mypy: Enable strict optional on lib/soft_deactivation.

Tweaked by tabbott to add assert statements, rather than new
conditionals.
This commit is contained in:
jkiely
2018-05-17 13:09:03 -04:00
committed by Tim Abbott
parent d4119d0198
commit 058ee1ce1e
2 changed files with 8 additions and 6 deletions

View File

@@ -312,7 +312,7 @@ strict_optional = True
[mypy-zerver.lib.avatar] # str vs Optional[str] [mypy-zerver.lib.avatar] # str vs Optional[str]
strict_optional = True strict_optional = True
[mypy-zerver.lib.soft_deactivation] [mypy-zerver.lib.soft_deactivation]
strict_optional = False strict_optional = True
[mypy-zerver.lib.events] # signup_notifications_stream is Optional, but accessing id property [mypy-zerver.lib.events] # signup_notifications_stream is Optional, but accessing id property
strict_optional = True strict_optional = True
[mypy-zerver.lib.exceptions] #21: error: Return type of "__reduce_ex__" incompatible with supertype "object" [mypy-zerver.lib.exceptions] #21: error: Return type of "__reduce_ex__" incompatible with supertype "object"

View File

@@ -97,6 +97,7 @@ def add_missing_messages(user_profile: UserProfile) -> None:
* Create the UserMessage rows. * Create the UserMessage rows.
""" """
assert user_profile.last_active_message_id is not None
all_stream_subs = list(Subscription.objects.select_related('recipient').filter( all_stream_subs = list(Subscription.objects.select_related('recipient').filter(
user_profile=user_profile, user_profile=user_profile,
recipient__type=Recipient.STREAM).values('recipient', 'recipient__type_id')) recipient__type=Recipient.STREAM).values('recipient', 'recipient__type_id'))
@@ -118,8 +119,9 @@ def add_missing_messages(user_profile: UserProfile) -> None:
recipient_ids = [] recipient_ids = []
for sub in all_stream_subs: for sub in all_stream_subs:
stream_subscription_logs = all_stream_subscription_logs[sub['recipient__type_id']] stream_subscription_logs = all_stream_subscription_logs[sub['recipient__type_id']]
if (stream_subscription_logs[-1].event_type == 'subscription_deactivated' and if stream_subscription_logs[-1].event_type == 'subscription_deactivated':
stream_subscription_logs[-1].event_last_message_id <= user_profile.last_active_message_id): assert stream_subscription_logs[-1].event_last_message_id is not None
if stream_subscription_logs[-1].event_last_message_id <= user_profile.last_active_message_id:
# We are going to short circuit this iteration as its no use # We are going to short circuit this iteration as its no use
# iterating since user unsubscribed before soft-deactivation # iterating since user unsubscribed before soft-deactivation
continue continue