mypy: enable strict optional for lib/message.

Add assert in order to pass checks under strict conditions.
This commit is contained in:
jkiely
2018-05-17 12:12:50 -04:00
committed by Tim Abbott
parent 04c50cffa7
commit 104fdd8bf9
2 changed files with 3 additions and 1 deletions

View File

@@ -320,7 +320,7 @@ strict_optional = True
[mypy-zerver.lib.bugdown.api_arguments_table_generator] #18: error: Item "None" of "Optional[Dict[str, Any]]" has no attribute "items"
strict_optional = True
[mypy-zerver.lib.message] #868: error: Unsupported operand types for - ("Optional[int]" and "int")
strict_optional = False
strict_optional = True
[mypy-zerver.migrations.0077_add_file_name_field_to_realm_emoji] #73: error: Argument 2 to "upload_files" of "Uploader" has incompatible type "Optional[bytes]"; expected "bytes"
strict_optional = False

View File

@@ -893,6 +893,8 @@ def maybe_update_first_visible_message_id(realm: Realm, lookback_hours: int) ->
def update_first_visible_message_id(realm: Realm) -> None:
try:
# We have verified that the limit is not none before calling this function.
assert realm.message_visibility_limit is not None
first_visible_message_id = Message.objects.filter(sender__realm=realm).values('id').\
order_by('-id')[realm.message_visibility_limit - 1]["id"]
except IndexError: