mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
mypy: Clean up more optional types.
This commit is contained in:
@@ -1171,7 +1171,7 @@ def check_send_message(sender, client, message_type_name, message_to,
|
|||||||
subject_name, message_content, realm=None, forged=False,
|
subject_name, message_content, realm=None, forged=False,
|
||||||
forged_timestamp=None, forwarder_user_profile=None, local_id=None,
|
forged_timestamp=None, forwarder_user_profile=None, local_id=None,
|
||||||
sender_queue_id=None):
|
sender_queue_id=None):
|
||||||
# type: (UserProfile, Client, Text, Sequence[Text], Text, Text, Optional[Realm], bool, Optional[float], Optional[UserProfile], Optional[Text], Optional[Text]) -> int
|
# type: (UserProfile, Client, Text, Sequence[Text], Optional[Text], Text, Optional[Realm], bool, Optional[float], Optional[UserProfile], Optional[Text], Optional[Text]) -> int
|
||||||
message = check_message(sender, client, message_type_name, message_to,
|
message = check_message(sender, client, message_type_name, message_to,
|
||||||
subject_name, message_content, realm, forged, forged_timestamp,
|
subject_name, message_content, realm, forged, forged_timestamp,
|
||||||
forwarder_user_profile, local_id, sender_queue_id)
|
forwarder_user_profile, local_id, sender_queue_id)
|
||||||
@@ -1926,7 +1926,7 @@ def _default_stream_permision_check(user_profile, stream):
|
|||||||
raise JsonableError(_('Insufficient permission'))
|
raise JsonableError(_('Insufficient permission'))
|
||||||
|
|
||||||
def do_change_default_sending_stream(user_profile, stream, log=True):
|
def do_change_default_sending_stream(user_profile, stream, log=True):
|
||||||
# type: (UserProfile, Stream, bool) -> None
|
# type: (UserProfile, Optional[Stream], bool) -> None
|
||||||
_default_stream_permision_check(user_profile, stream)
|
_default_stream_permision_check(user_profile, stream)
|
||||||
|
|
||||||
user_profile.default_sending_stream = stream
|
user_profile.default_sending_stream = stream
|
||||||
@@ -1949,7 +1949,7 @@ def do_change_default_sending_stream(user_profile, stream, log=True):
|
|||||||
bot_owner_userids(user_profile))
|
bot_owner_userids(user_profile))
|
||||||
|
|
||||||
def do_change_default_events_register_stream(user_profile, stream, log=True):
|
def do_change_default_events_register_stream(user_profile, stream, log=True):
|
||||||
# type: (UserProfile, Stream, bool) -> None
|
# type: (UserProfile, Optional[Stream], bool) -> None
|
||||||
_default_stream_permision_check(user_profile, stream)
|
_default_stream_permision_check(user_profile, stream)
|
||||||
|
|
||||||
user_profile.default_events_register_stream = stream
|
user_profile.default_events_register_stream = stream
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ def log_into_subdomain(request):
|
|||||||
full_name, invalid_subdomain)
|
full_name, invalid_subdomain)
|
||||||
|
|
||||||
def get_dev_users(extra_users_count=10):
|
def get_dev_users(extra_users_count=10):
|
||||||
# type: (Optional[int]) -> List[UserProfile]
|
# type: (int) -> List[UserProfile]
|
||||||
# Development environments usually have only a few users, but
|
# Development environments usually have only a few users, but
|
||||||
# it still makes sense to limit how many extra users we render to
|
# it still makes sense to limit how many extra users we render to
|
||||||
# support performance testing with DevAuthBackend.
|
# support performance testing with DevAuthBackend.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from zerver.lib.events import do_events_register
|
|||||||
from zerver.lib.request import REQ, has_request_variables
|
from zerver.lib.request import REQ, has_request_variables
|
||||||
from zerver.lib.response import json_success
|
from zerver.lib.response import json_success
|
||||||
from zerver.lib.validator import check_string, check_list, check_bool
|
from zerver.lib.validator import check_string, check_list, check_bool
|
||||||
from zerver.models import UserProfile
|
from zerver.models import Stream, UserProfile
|
||||||
|
|
||||||
def _default_all_public_streams(user_profile, all_public_streams):
|
def _default_all_public_streams(user_profile, all_public_streams):
|
||||||
# type: (UserProfile, Optional[bool]) -> bool
|
# type: (UserProfile, Optional[bool]) -> bool
|
||||||
@@ -19,7 +19,7 @@ def _default_all_public_streams(user_profile, all_public_streams):
|
|||||||
|
|
||||||
def _default_narrow(user_profile, narrow):
|
def _default_narrow(user_profile, narrow):
|
||||||
# type: (UserProfile, Iterable[Sequence[Text]]) -> Iterable[Sequence[Text]]
|
# type: (UserProfile, Iterable[Sequence[Text]]) -> Iterable[Sequence[Text]]
|
||||||
default_stream = user_profile.default_events_register_stream
|
default_stream = user_profile.default_events_register_stream # type: Optional[Stream]
|
||||||
if not narrow and user_profile.default_events_register_stream is not None:
|
if not narrow and user_profile.default_events_register_stream is not None:
|
||||||
narrow = [['stream', default_stream.name]]
|
narrow = [['stream', default_stream.name]]
|
||||||
return narrow
|
return narrow
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ def approximate_unread_count(user_profile):
|
|||||||
flags=UserMessage.flags.read).count()
|
flags=UserMessage.flags.read).count()
|
||||||
|
|
||||||
def sent_time_in_epoch_seconds(user_message):
|
def sent_time_in_epoch_seconds(user_message):
|
||||||
# type: (UserMessage) -> float
|
# type: (UserMessage) -> Optional[float]
|
||||||
# user_message is a UserMessage object.
|
# user_message is a UserMessage object.
|
||||||
if not user_message:
|
if not user_message:
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ from django.conf import settings
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from typing import Text
|
from typing import Optional, Set, Text
|
||||||
from typing import Set
|
|
||||||
|
|
||||||
from zerver.decorator import authenticated_json_post_view
|
from zerver.decorator import authenticated_json_post_view
|
||||||
from zerver.lib.actions import do_invite_users, do_refer_friend, \
|
from zerver.lib.actions import do_invite_users, do_refer_friend, \
|
||||||
@@ -33,7 +32,7 @@ def json_invite_users(request, user_profile, invitee_emails_raw=REQ("invitee_ema
|
|||||||
|
|
||||||
# We unconditionally sub you to the notifications stream if it
|
# We unconditionally sub you to the notifications stream if it
|
||||||
# exists and is public.
|
# exists and is public.
|
||||||
notifications_stream = user_profile.realm.notifications_stream
|
notifications_stream = user_profile.realm.notifications_stream # type: Optional[Stream]
|
||||||
if notifications_stream and not notifications_stream.invite_only:
|
if notifications_stream and not notifications_stream.invite_only:
|
||||||
stream_names.append(notifications_stream.name)
|
stream_names.append(notifications_stream.name)
|
||||||
|
|
||||||
|
|||||||
@@ -358,7 +358,7 @@ def get_search_fields(rendered_content, subject, content_matches, subject_matche
|
|||||||
match_subject=highlight_string(escape_html(subject), subject_matches))
|
match_subject=highlight_string(escape_html(subject), subject_matches))
|
||||||
|
|
||||||
def narrow_parameter(json):
|
def narrow_parameter(json):
|
||||||
# type: (str) -> List[Dict[str, Any]]
|
# type: (str) -> Optional[List[Dict[str, Any]]]
|
||||||
|
|
||||||
# FIXME: A hack to support old mobile clients
|
# FIXME: A hack to support old mobile clients
|
||||||
if json == '{}':
|
if json == '{}':
|
||||||
@@ -419,7 +419,7 @@ def is_public_stream(stream_name, realm):
|
|||||||
|
|
||||||
|
|
||||||
def ok_to_include_history(narrow, realm):
|
def ok_to_include_history(narrow, realm):
|
||||||
# type: (Iterable[Dict[str, Any]], Realm) -> bool
|
# type: (Optional[Iterable[Dict[str, Any]]], Realm) -> bool
|
||||||
|
|
||||||
# There are occasions where we need to find Message rows that
|
# There are occasions where we need to find Message rows that
|
||||||
# have no corresponding UserMessage row, because the user is
|
# have no corresponding UserMessage row, because the user is
|
||||||
@@ -454,7 +454,7 @@ def get_stream_name_from_narrow(narrow):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def exclude_muting_conditions(user_profile, narrow):
|
def exclude_muting_conditions(user_profile, narrow):
|
||||||
# type: (UserProfile, Iterable[Dict[str, Any]]) -> List[Selectable]
|
# type: (UserProfile, Optional[Iterable[Dict[str, Any]]]) -> List[Selectable]
|
||||||
conditions = []
|
conditions = []
|
||||||
stream_name = get_stream_name_from_narrow(narrow)
|
stream_name = get_stream_name_from_narrow(narrow)
|
||||||
|
|
||||||
@@ -716,7 +716,7 @@ def update_message_flags(request, user_profile,
|
|||||||
'msg': ''})
|
'msg': ''})
|
||||||
|
|
||||||
def create_mirrored_message_users(request, user_profile, recipients):
|
def create_mirrored_message_users(request, user_profile, recipients):
|
||||||
# type: (HttpResponse, UserProfile, Iterable[Text]) -> Tuple[bool, UserProfile]
|
# type: (HttpResponse, UserProfile, Iterable[Text]) -> Tuple[bool, Optional[UserProfile]]
|
||||||
if "sender" not in request.POST:
|
if "sender" not in request.POST:
|
||||||
return (False, None)
|
return (False, None)
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from zerver.lib.utils import statsd, statsd_key
|
|||||||
from zerver.lib.validator import check_bool, check_dict
|
from zerver.lib.validator import check_bool, check_dict
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
from typing import Text
|
from typing import Optional, Text
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
@@ -89,7 +89,8 @@ def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
|
|||||||
stacktrace = js_source_map.annotate_stacktrace(stacktrace)
|
stacktrace = js_source_map.annotate_stacktrace(stacktrace)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
version = subprocess.check_output(["git", "log", "HEAD^..HEAD", "--oneline"], universal_newlines=True)
|
version = subprocess.check_output(["git", "log", "HEAD^..HEAD", "--oneline"],
|
||||||
|
universal_newlines=True) # type: Optional[Text]
|
||||||
except Exception:
|
except Exception:
|
||||||
version = None
|
version = None
|
||||||
|
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ def add_subscriptions_backend(request, user_profile,
|
|||||||
"private", email, "", msg))
|
"private", email, "", msg))
|
||||||
|
|
||||||
if announce and len(created_streams) > 0:
|
if announce and len(created_streams) > 0:
|
||||||
notifications_stream = user_profile.realm.notifications_stream
|
notifications_stream = user_profile.realm.notifications_stream # type: Optional[Stream]
|
||||||
if notifications_stream is not None:
|
if notifications_stream is not None:
|
||||||
if len(created_streams) > 1:
|
if len(created_streams) > 1:
|
||||||
stream_msg = "the following streams: %s" % (", ".join('#**%s**' % s.name for s in created_streams))
|
stream_msg = "the following streams: %s" % (", ".join('#**%s**' % s.name for s in created_streams))
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ def patch_bot_backend(request, user_profile, email,
|
|||||||
check_change_full_name(bot, full_name)
|
check_change_full_name(bot, full_name)
|
||||||
if default_sending_stream is not None:
|
if default_sending_stream is not None:
|
||||||
if default_sending_stream == "":
|
if default_sending_stream == "":
|
||||||
stream = None
|
stream = None # type: Optional[Stream]
|
||||||
else:
|
else:
|
||||||
(stream, recipient, sub) = access_stream_by_name(
|
(stream, recipient, sub) = access_stream_by_name(
|
||||||
user_profile, default_sending_stream)
|
user_profile, default_sending_stream)
|
||||||
|
|||||||
Reference in New Issue
Block a user