mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
mypy: Various strict-optional fixes in zerver.
This commit is contained in:
committed by
Tim Abbott
parent
004ff1ae4d
commit
2311e169ec
@@ -67,7 +67,7 @@ class BugdownRenderingException(Exception):
|
|||||||
def url_embed_preview_enabled_for_realm(message):
|
def url_embed_preview_enabled_for_realm(message):
|
||||||
# type: (Optional[Message]) -> bool
|
# type: (Optional[Message]) -> bool
|
||||||
if message is not None:
|
if message is not None:
|
||||||
realm = message.get_realm()
|
realm = message.get_realm() # type: Optional[Realm]
|
||||||
else:
|
else:
|
||||||
realm = None
|
realm = None
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ def image_preview_enabled_for_realm():
|
|||||||
# type: () -> bool
|
# type: () -> bool
|
||||||
global current_message
|
global current_message
|
||||||
if current_message is not None:
|
if current_message is not None:
|
||||||
realm = current_message.get_realm()
|
realm = current_message.get_realm() # type: Optional[Realm]
|
||||||
else:
|
else:
|
||||||
realm = None
|
realm = None
|
||||||
if not settings.INLINE_IMAGE_PREVIEW:
|
if not settings.INLINE_IMAGE_PREVIEW:
|
||||||
@@ -1457,7 +1457,7 @@ def do_convert(content, message=None, message_realm=None, possible_words=None, s
|
|||||||
# * Nothing is passed in other than content -> just run default options (e.g. for docs)
|
# * Nothing is passed in other than content -> just run default options (e.g. for docs)
|
||||||
# * message is passed, but no realm is -> look up realm from message
|
# * message is passed, but no realm is -> look up realm from message
|
||||||
# * message_realm is passed -> use that realm for bugdown purposes
|
# * message_realm is passed -> use that realm for bugdown purposes
|
||||||
if message:
|
if message is not None:
|
||||||
if message_realm is None:
|
if message_realm is None:
|
||||||
message_realm = message.get_realm()
|
message_realm = message.get_realm()
|
||||||
if message_realm is None:
|
if message_realm is None:
|
||||||
@@ -1488,7 +1488,8 @@ def do_convert(content, message=None, message_realm=None, possible_words=None, s
|
|||||||
|
|
||||||
# Pre-fetch data from the DB that is used in the bugdown thread
|
# Pre-fetch data from the DB that is used in the bugdown thread
|
||||||
global db_data
|
global db_data
|
||||||
if message:
|
if message is not None:
|
||||||
|
assert message_realm is not None # ensured above if message is not None
|
||||||
realm_users = get_active_user_dicts_in_realm(message_realm)
|
realm_users = get_active_user_dicts_in_realm(message_realm)
|
||||||
realm_streams = get_active_streams(message_realm).values('id', 'name')
|
realm_streams = get_active_streams(message_realm).values('id', 'name')
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ def build_message_list(user_profile, messages):
|
|||||||
plain = fix_plaintext_image_urls(plain)
|
plain = fix_plaintext_image_urls(plain)
|
||||||
plain = relative_to_full_url(plain)
|
plain = relative_to_full_url(plain)
|
||||||
|
|
||||||
|
assert message.rendered_content is not None
|
||||||
html = message.rendered_content
|
html = message.rendered_content
|
||||||
html = relative_to_full_url(html)
|
html = relative_to_full_url(html)
|
||||||
html = fix_emoji_sizes(html)
|
html = fix_emoji_sizes(html)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ def timeout(timeout, func, *args, **kwargs):
|
|||||||
# type: () -> None
|
# type: () -> None
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.result = None # type: Optional[ResultT]
|
self.result = None # type: Optional[ResultT]
|
||||||
self.exc_info = None # type: Optional[Tuple[Type[BaseException], BaseException, TracebackType]]
|
self.exc_info = None # type: Optional[Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]]
|
||||||
|
|
||||||
# Don't block the whole program from exiting
|
# Don't block the whole program from exiting
|
||||||
# if this is the only thread left.
|
# if this is the only thread left.
|
||||||
@@ -92,4 +92,5 @@ def timeout(timeout, func, *args, **kwargs):
|
|||||||
# Raise the original stack trace so our error messages are more useful.
|
# Raise the original stack trace so our error messages are more useful.
|
||||||
# from http://stackoverflow.com/a/4785766/90777
|
# from http://stackoverflow.com/a/4785766/90777
|
||||||
six.reraise(thread.exc_info[0], thread.exc_info[1], thread.exc_info[2])
|
six.reraise(thread.exc_info[0], thread.exc_info[1], thread.exc_info[2])
|
||||||
|
assert thread.result is not None # assured if above did not reraise
|
||||||
return thread.result
|
return thread.result
|
||||||
|
|||||||
@@ -228,7 +228,9 @@ def get_file_info(request, user_file):
|
|||||||
if guessed_type is not None:
|
if guessed_type is not None:
|
||||||
content_type = force_text(guessed_type)
|
content_type = force_text(guessed_type)
|
||||||
else:
|
else:
|
||||||
uploaded_file_name = uploaded_file_name + guess_extension(content_type)
|
extension = guess_extension(content_type)
|
||||||
|
if extension is not None:
|
||||||
|
uploaded_file_name = uploaded_file_name + extension
|
||||||
|
|
||||||
uploaded_file_name = urllib.parse.unquote(uploaded_file_name)
|
uploaded_file_name = urllib.parse.unquote(uploaded_file_name)
|
||||||
uploaded_file_size = user_file.size
|
uploaded_file_size = user_file.size
|
||||||
|
|||||||
@@ -963,7 +963,7 @@ def get_stream_backend(stream_name, realm):
|
|||||||
name__iexact=stream_name.strip(), realm_id=realm.id)
|
name__iexact=stream_name.strip(), realm_id=realm.id)
|
||||||
|
|
||||||
def get_active_streams(realm):
|
def get_active_streams(realm):
|
||||||
# type: (Realm) -> QuerySet
|
# type: (Optional[Realm]) -> QuerySet
|
||||||
"""
|
"""
|
||||||
Return all streams (including invite-only streams) that have not been deactivated.
|
Return all streams (including invite-only streams) that have not been deactivated.
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user