mypy: Use Python 3 type syntax in zerver/views/messages.py.

This commit is contained in:
picapi_ 2017-12-03 17:46:27 +00:00 committed by showell
parent ff435439af
commit e2c14724d9
1 changed files with 41 additions and 48 deletions

View File

@ -555,15 +555,15 @@ def exclude_muting_conditions(user_profile: UserProfile,
return conditions return conditions
@has_request_variables @has_request_variables
def get_messages_backend(request, user_profile, def get_messages_backend(request: HttpRequest, user_profile: UserProfile,
anchor = REQ(converter=int), anchor: int=REQ(converter=int),
num_before = REQ(converter=to_non_negative_int), num_before: int=REQ(converter=to_non_negative_int),
num_after = REQ(converter=to_non_negative_int), num_after: int=REQ(converter=to_non_negative_int),
narrow = REQ('narrow', converter=narrow_parameter, default=None), narrow: Optional[List[Dict[str, Any]]]=REQ('narrow', converter=narrow_parameter,
use_first_unread_anchor = REQ(validator=check_bool, default=False), default=None),
client_gravatar = REQ(validator=check_bool, default=False), use_first_unread_anchor: bool=REQ(validator=check_bool, default=False),
apply_markdown = REQ(validator=check_bool, default=True)): client_gravatar: bool=REQ(validator=check_bool, default=False),
# type: (HttpRequest, UserProfile, int, int, int, Optional[List[Dict[str, Any]]], bool, bool, bool) -> HttpResponse apply_markdown: bool=REQ(validator=check_bool, default=True)) -> HttpResponse:
include_history = ok_to_include_history(narrow, user_profile.realm) include_history = ok_to_include_history(narrow, user_profile.realm)
if include_history and not use_first_unread_anchor: if include_history and not use_first_unread_anchor:
@ -755,10 +755,9 @@ def get_messages_backend(request, user_profile,
return json_success(ret) return json_success(ret)
@has_request_variables @has_request_variables
def update_message_flags(request, user_profile, def update_message_flags(request: HttpRequest, user_profile: UserProfile,
messages=REQ(validator=check_list(check_int)), messages: List[int]=REQ(validator=check_list(check_int)),
operation=REQ('op'), flag=REQ()): operation: Text=REQ('op'), flag: Text=REQ()) -> HttpResponse:
# type: (HttpRequest, UserProfile, List[int], Text, Text) -> HttpResponse
count = do_update_message_flags(user_profile, operation, flag, messages) count = do_update_message_flags(user_profile, operation, flag, messages)
@ -781,10 +780,9 @@ def mark_all_as_read(request: HttpRequest, user_profile: UserProfile) -> HttpRes
'msg': ''}) 'msg': ''})
@has_request_variables @has_request_variables
def mark_stream_as_read(request, def mark_stream_as_read(request: HttpRequest,
user_profile, user_profile: UserProfile,
stream_id=REQ(validator=check_int)): stream_id: int=REQ(validator=check_int)) -> HttpResponse:
# type: (HttpRequest, UserProfile, int) -> HttpResponse
stream, recipient, sub = access_stream_by_id(user_profile, stream_id) stream, recipient, sub = access_stream_by_id(user_profile, stream_id)
count = do_mark_stream_messages_as_read(user_profile, stream) count = do_mark_stream_messages_as_read(user_profile, stream)
@ -795,11 +793,10 @@ def mark_stream_as_read(request,
'msg': ''}) 'msg': ''})
@has_request_variables @has_request_variables
def mark_topic_as_read(request, def mark_topic_as_read(request: HttpRequest,
user_profile, user_profile: UserProfile,
stream_id=REQ(validator=check_int), stream_id: int=REQ(validator=check_int),
topic_name=REQ()): topic_name: Text=REQ()) -> HttpResponse:
# type: (HttpRequest, UserProfile, int, Text) -> HttpResponse
stream, recipient, sub = access_stream_by_id(user_profile, stream_id) stream, recipient, sub = access_stream_by_id(user_profile, stream_id)
if topic_name: if topic_name:
@ -906,16 +903,15 @@ def same_realm_jabber_user(user_profile: UserProfile, email: Text) -> bool:
# send_message_backend should either check the API key or check that # send_message_backend should either check the API key or check that
# the user is logged in. # the user is logged in.
@has_request_variables @has_request_variables
def send_message_backend(request, user_profile, def send_message_backend(request: HttpRequest, user_profile: UserProfile,
message_type_name = REQ('type'), message_type_name: Text=REQ('type'),
message_to = REQ('to', converter=extract_recipients, default=[]), message_to: List[Text]=REQ('to', converter=extract_recipients, default=[]),
forged = REQ(default=False), forged: bool=REQ(default=False),
topic_name = REQ('subject', lambda x: x.strip(), None), topic_name: Optional[Text]=REQ('subject', lambda x: x.strip(), None),
message_content = REQ('content'), message_content: Text=REQ('content'),
realm_str = REQ('realm_str', default=None), realm_str: Optional[Text]=REQ('realm_str', default=None),
local_id = REQ(default=None), local_id: Optional[Text]=REQ(default=None),
queue_id = REQ(default=None)): queue_id: Optional[Text]=REQ(default=None)) -> HttpResponse:
# type: (HttpRequest, UserProfile, Text, List[Text], bool, Optional[Text], Text, Optional[Text], Optional[Text], Optional[Text]) -> HttpResponse
client = request.client client = request.client
is_super_user = request.user.is_api_super_user is_super_user = request.user.is_api_super_user
if forged and not is_super_user: if forged and not is_super_user:
@ -1014,9 +1010,8 @@ def fill_edit_history_entries(message_history: List[Dict[str, Any]], message: Me
)) ))
@has_request_variables @has_request_variables
def get_message_edit_history(request, user_profile, def get_message_edit_history(request: HttpRequest, user_profile: UserProfile,
message_id=REQ(converter=to_non_negative_int)): message_id: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
# type: (HttpRequest, UserProfile, int) -> HttpResponse
if not user_profile.realm.allow_edit_history: if not user_profile.realm.allow_edit_history:
return json_error(_("Message edit history is disabled in this organization")) return json_error(_("Message edit history is disabled in this organization"))
message, ignored_user_message = access_message(user_profile, message_id) message, ignored_user_message = access_message(user_profile, message_id)
@ -1029,12 +1024,11 @@ def get_message_edit_history(request, user_profile,
return json_success({"message_history": reversed(message_edit_history)}) return json_success({"message_history": reversed(message_edit_history)})
@has_request_variables @has_request_variables
def update_message_backend(request, user_profile, def update_message_backend(request: HttpRequest, user_profile: UserMessage,
message_id=REQ(converter=to_non_negative_int), message_id: int=REQ(converter=to_non_negative_int),
subject=REQ(default=None), subject: Optional[Text]=REQ(default=None),
propagate_mode=REQ(default="change_one"), propagate_mode: Optional[str]=REQ(default="change_one"),
content=REQ(default=None)): content: Optional[Text]=REQ(default=None)) -> HttpResponse:
# type: (HttpRequest, UserProfile, int, Optional[Text], Optional[str], Optional[Text]) -> HttpResponse
if not user_profile.realm.allow_message_editing: if not user_profile.realm.allow_message_editing:
return json_error(_("Your organization has turned off message editing")) return json_error(_("Your organization has turned off message editing"))
@ -1127,9 +1121,8 @@ def delete_message_backend(request: HttpRequest, user_profile: UserProfile,
return json_success() return json_success()
@has_request_variables @has_request_variables
def json_fetch_raw_message(request, user_profile, def json_fetch_raw_message(request: HttpRequest, user_profile: UserProfile,
message_id=REQ(converter=to_non_negative_int)): message_id: int=REQ(converter=to_non_negative_int)) -> HttpResponse:
# type: (HttpRequest, UserProfile, int) -> HttpResponse
(message, user_message) = access_message(user_profile, message_id) (message, user_message) = access_message(user_profile, message_id)
return json_success({"raw_content": message.content}) return json_success({"raw_content": message.content})
@ -1145,10 +1138,10 @@ def render_message_backend(request: HttpRequest, user_profile: UserProfile,
return json_success({"rendered": rendered_content}) return json_success({"rendered": rendered_content})
@has_request_variables @has_request_variables
def messages_in_narrow_backend(request, user_profile, def messages_in_narrow_backend(request: HttpRequest, user_profile: UserProfile,
msg_ids = REQ(validator=check_list(check_int)), msg_ids: List[int]=REQ(validator=check_list(check_int)),
narrow = REQ(converter=narrow_parameter)): narrow: Optional[List[Dict[str, Any]]]=REQ(converter=narrow_parameter)
# type: (HttpRequest, UserProfile, List[int], Optional[List[Dict[str, Any]]]) -> HttpResponse ) -> HttpResponse:
# This query is limited to messages the user has access to because they # This query is limited to messages the user has access to because they
# actually received them, as reflected in `zerver_usermessage`. # actually received them, as reflected in `zerver_usermessage`.