mypy: Clean up more optional types.

This commit is contained in:
Tim Abbott
2017-02-10 20:45:39 -08:00
parent aee81b702c
commit eeca69cb4b
9 changed files with 18 additions and 18 deletions

View File

@@ -1171,7 +1171,7 @@ def check_send_message(sender, client, message_type_name, message_to,
subject_name, message_content, realm=None, forged=False,
forged_timestamp=None, forwarder_user_profile=None, local_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,
subject_name, message_content, realm, forged, forged_timestamp,
forwarder_user_profile, local_id, sender_queue_id)
@@ -1926,7 +1926,7 @@ def _default_stream_permision_check(user_profile, stream):
raise JsonableError(_('Insufficient permission'))
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)
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))
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)
user_profile.default_events_register_stream = stream

View File

@@ -326,7 +326,7 @@ def log_into_subdomain(request):
full_name, invalid_subdomain)
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
# it still makes sense to limit how many extra users we render to
# support performance testing with DevAuthBackend.

View File

@@ -8,7 +8,7 @@ from zerver.lib.events import do_events_register
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
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):
# 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):
# 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:
narrow = [['stream', default_stream.name]]
return narrow

View File

@@ -76,7 +76,7 @@ def approximate_unread_count(user_profile):
flags=UserMessage.flags.read).count()
def sent_time_in_epoch_seconds(user_message):
# type: (UserMessage) -> float
# type: (UserMessage) -> Optional[float]
# user_message is a UserMessage object.
if not user_message:
return None

View File

@@ -4,8 +4,7 @@ from django.conf import settings
from django.core.exceptions import ValidationError
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from typing import Text
from typing import Set
from typing import Optional, Set, Text
from zerver.decorator import authenticated_json_post_view
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
# 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:
stream_names.append(notifications_stream.name)

View File

@@ -358,7 +358,7 @@ def get_search_fields(rendered_content, subject, content_matches, subject_matche
match_subject=highlight_string(escape_html(subject), subject_matches))
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
if json == '{}':
@@ -419,7 +419,7 @@ def is_public_stream(stream_name, 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
# have no corresponding UserMessage row, because the user is
@@ -454,7 +454,7 @@ def get_stream_name_from_narrow(narrow):
return None
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 = []
stream_name = get_stream_name_from_narrow(narrow)
@@ -716,7 +716,7 @@ def update_message_flags(request, user_profile,
'msg': ''})
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:
return (False, None)

View File

@@ -13,7 +13,7 @@ from zerver.lib.utils import statsd, statsd_key
from zerver.lib.validator import check_bool, check_dict
from zerver.models import UserProfile
from typing import Text
from typing import Optional, Text
import subprocess
import os
@@ -89,7 +89,8 @@ def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
stacktrace = js_source_map.annotate_stacktrace(stacktrace)
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:
version = None

View File

@@ -276,7 +276,7 @@ def add_subscriptions_backend(request, user_profile,
"private", email, "", msg))
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 len(created_streams) > 1:
stream_msg = "the following streams: %s" % (", ".join('#**%s**' % s.name for s in created_streams))

View File

@@ -154,7 +154,7 @@ def patch_bot_backend(request, user_profile, email,
check_change_full_name(bot, full_name)
if default_sending_stream is not None:
if default_sending_stream == "":
stream = None
stream = None # type: Optional[Stream]
else:
(stream, recipient, sub) = access_stream_by_name(
user_profile, default_sending_stream)