mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 23:19:10 +00:00
mypy: Use Python 3 type syntax in several files.
This commit is contained in:
@@ -6,7 +6,6 @@ import time
|
|||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
if False:
|
|
||||||
from typing import (Any, Iterator, Optional)
|
from typing import (Any, Iterator, Optional)
|
||||||
|
|
||||||
# Verify the Zulip venv is available.
|
# Verify the Zulip venv is available.
|
||||||
@@ -49,9 +48,9 @@ def server_is_up(server, log_file):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def test_server_running(force=False, external_host='testserver',
|
def test_server_running(force: bool=False, external_host: str='testserver',
|
||||||
log_file=None, dots=False, use_db=True):
|
log_file: str=None, dots: bool=False, use_db: bool=True
|
||||||
# type: (bool, str, str, bool, bool) -> Iterator[None]
|
) -> Iterator[None]:
|
||||||
log = sys.stdout
|
log = sys.stdout
|
||||||
if log_file:
|
if log_file:
|
||||||
if os.path.exists(log_file) and os.path.getsize(log_file) < 100000:
|
if os.path.exists(log_file) and os.path.getsize(log_file) < 100000:
|
||||||
|
|||||||
@@ -530,9 +530,9 @@ def upload_icon_image(user_file: File, user_profile: UserProfile) -> None:
|
|||||||
def upload_emoji_image(emoji_file: File, emoji_file_name: Text, user_profile: UserProfile) -> None:
|
def upload_emoji_image(emoji_file: File, emoji_file_name: Text, user_profile: UserProfile) -> None:
|
||||||
upload_backend.upload_emoji_image(emoji_file, emoji_file_name, user_profile)
|
upload_backend.upload_emoji_image(emoji_file, emoji_file_name, user_profile)
|
||||||
|
|
||||||
def upload_message_image(uploaded_file_name, uploaded_file_size,
|
def upload_message_image(uploaded_file_name: Text, uploaded_file_size: int,
|
||||||
content_type, file_data, user_profile, target_realm=None):
|
content_type: Optional[Text], file_data: bytes,
|
||||||
# type: (Text, int, Optional[Text], bytes, UserProfile, Optional[Realm]) -> Text
|
user_profile: UserProfile, target_realm: Optional[Realm]=None) -> Text:
|
||||||
return upload_backend.upload_message_image(uploaded_file_name, uploaded_file_size,
|
return upload_backend.upload_message_image(uploaded_file_name, uploaded_file_size,
|
||||||
content_type, file_data, user_profile,
|
content_type, file_data, user_profile,
|
||||||
target_realm=target_realm)
|
target_realm=target_realm)
|
||||||
|
|||||||
@@ -549,10 +549,11 @@ def extract_json_response(resp: requests.Response) -> Dict[str, Any]:
|
|||||||
else:
|
else:
|
||||||
return resp.json # type: ignore # mypy trusts the stub, not the runtime type checking of this fn
|
return resp.json # type: ignore # mypy trusts the stub, not the runtime type checking of this fn
|
||||||
|
|
||||||
def request_event_queue(user_profile, user_client, apply_markdown, client_gravatar,
|
def request_event_queue(user_profile: UserProfile, user_client: Client, apply_markdown: bool,
|
||||||
queue_lifespan_secs, event_types=None, all_public_streams=False,
|
client_gravatar: bool, queue_lifespan_secs: int,
|
||||||
narrow=[]):
|
event_types: Optional[Iterable[str]]=None,
|
||||||
# type: (UserProfile, Client, bool, bool, int, Optional[Iterable[str]], bool, Iterable[Sequence[Text]]) -> Optional[str]
|
all_public_streams: bool=False,
|
||||||
|
narrow: Iterable[Sequence[Text]]=[]) -> Optional[str]:
|
||||||
if settings.TORNADO_SERVER:
|
if settings.TORNADO_SERVER:
|
||||||
req = {'dont_block': 'true',
|
req = {'dont_block': 'true',
|
||||||
'apply_markdown': ujson.dumps(apply_markdown),
|
'apply_markdown': ujson.dumps(apply_markdown),
|
||||||
|
|||||||
@@ -36,18 +36,18 @@ def cleanup_event_queue(request: HttpRequest, user_profile: UserProfile,
|
|||||||
|
|
||||||
@asynchronous
|
@asynchronous
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def get_events_backend(request, user_profile, handler,
|
def get_events_backend(request: HttpRequest, user_profile: UserProfile, handler: BaseHandler,
|
||||||
user_client = REQ(converter=get_client, default=None),
|
user_client: Optional[Client]=REQ(converter=get_client, default=None),
|
||||||
last_event_id = REQ(converter=int, default=None),
|
last_event_id: Optional[int]=REQ(converter=int, default=None),
|
||||||
queue_id = REQ(default=None),
|
queue_id: Optional[List[Text]]=REQ(default=None),
|
||||||
apply_markdown = REQ(default=False, validator=check_bool),
|
apply_markdown: bool=REQ(default=False, validator=check_bool),
|
||||||
client_gravatar = REQ(default=False, validator=check_bool),
|
client_gravatar: bool=REQ(default=False, validator=check_bool),
|
||||||
all_public_streams = REQ(default=False, validator=check_bool),
|
all_public_streams: bool=REQ(default=False, validator=check_bool),
|
||||||
event_types = REQ(default=None, validator=check_list(check_string)),
|
event_types: Optional[Text]=REQ(default=None, validator=check_list(check_string)),
|
||||||
dont_block = REQ(default=False, validator=check_bool),
|
dont_block: bool=REQ(default=False, validator=check_bool),
|
||||||
narrow = REQ(default=[], validator=check_list(None)),
|
narrow: Iterable[Sequence[Text]]=REQ(default=[], validator=check_list(None)),
|
||||||
lifespan_secs = REQ(default=0, converter=int)):
|
lifespan_secs: int=REQ(default=0, converter=int)
|
||||||
# type: (HttpRequest, UserProfile, BaseHandler, Optional[Client], Optional[int], Optional[List[Text]], bool, bool, bool, Optional[Text], bool, Iterable[Sequence[Text]], int) -> Union[HttpResponse, _RespondAsynchronously]
|
) -> Union[HttpResponse, _RespondAsynchronously]:
|
||||||
if user_client is None:
|
if user_client is None:
|
||||||
user_client = request.client
|
user_client = request.client
|
||||||
|
|
||||||
|
|||||||
@@ -124,9 +124,9 @@ def api_github_v1(user_profile: UserProfile,
|
|||||||
stream, commit_stream, issue_stream, **kwargs)
|
stream, commit_stream, issue_stream, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def api_github_v2(user_profile, event, payload, branches, default_stream,
|
def api_github_v2(user_profile: UserProfile, event: Text, payload: Mapping[Text, Any],
|
||||||
commit_stream, issue_stream, topic_focus = None):
|
branches: Text, default_stream: Text, commit_stream: Text,
|
||||||
# type: (UserProfile, Text, Mapping[Text, Any], Text, Text, Text, Text, Optional[Text]) -> Tuple[Text, Text, Text]
|
issue_stream: Text, topic_focus: Optional[Text]=None) -> Tuple[Text, Text, Text]:
|
||||||
"""
|
"""
|
||||||
processes github payload with version 2 field specification
|
processes github payload with version 2 field specification
|
||||||
`payload` comes in unmodified from github
|
`payload` comes in unmodified from github
|
||||||
@@ -194,19 +194,18 @@ def api_github_v2(user_profile, event, payload, branches, default_stream,
|
|||||||
|
|
||||||
@authenticated_api_view(is_webhook=True)
|
@authenticated_api_view(is_webhook=True)
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_github_landing(request, user_profile, event=REQ(),
|
def api_github_landing(request: HttpRequest, user_profile: UserProfile, event: Text=REQ(),
|
||||||
payload=REQ(validator=check_dict([])),
|
payload: Mapping[Text, Any]=REQ(validator=check_dict([])),
|
||||||
branches=REQ(default=''),
|
branches: Text=REQ(default=''),
|
||||||
stream=REQ(default=''),
|
stream: Text=REQ(default=''),
|
||||||
version=REQ(converter=to_non_negative_int, default=1),
|
version: int=REQ(converter=to_non_negative_int, default=1),
|
||||||
commit_stream=REQ(default=''),
|
commit_stream: Text=REQ(default=''),
|
||||||
issue_stream=REQ(default=''),
|
issue_stream: Text=REQ(default=''),
|
||||||
exclude_pull_requests=REQ(converter=flexible_boolean, default=False),
|
exclude_pull_requests: bool=REQ(converter=flexible_boolean, default=False),
|
||||||
exclude_issues=REQ(converter=flexible_boolean, default=False),
|
exclude_issues: bool=REQ(converter=flexible_boolean, default=False),
|
||||||
exclude_commits=REQ(converter=flexible_boolean, default=False),
|
exclude_commits: bool=REQ(converter=flexible_boolean, default=False),
|
||||||
emphasize_branch_in_topic=REQ(converter=flexible_boolean, default=False),
|
emphasize_branch_in_topic: bool=REQ(converter=flexible_boolean, default=False),
|
||||||
):
|
) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, Text, Mapping[Text, Any], Text, Text, int, Text, Text, bool, bool, bool, bool) -> HttpResponse
|
|
||||||
|
|
||||||
repository = payload['repository']
|
repository = payload['repository']
|
||||||
|
|
||||||
@@ -280,9 +279,11 @@ def api_github_landing(request, user_profile, event=REQ(),
|
|||||||
forged=False, topic_name=subject,
|
forged=False, topic_name=subject,
|
||||||
message_content=content)
|
message_content=content)
|
||||||
|
|
||||||
def build_message_from_gitlog(user_profile, name, ref, commits, before, after,
|
def build_message_from_gitlog(user_profile: UserProfile, name: Text, ref: Text,
|
||||||
url, pusher, forced=None, created=None, deleted=False):
|
commits: List[Dict[str, str]], before: Text, after: Text,
|
||||||
# type: (UserProfile, Text, Text, List[Dict[str, str]], Text, Text, Text, Text, Optional[Text], Optional[Text], Optional[bool]) -> Tuple[Text, Text]
|
url: Text, pusher: Text, forced: Optional[Text]=None,
|
||||||
|
created: Optional[Text]=None, deleted: Optional[bool]=False
|
||||||
|
) -> Tuple[Text, Text]:
|
||||||
short_ref = re.sub(r'^refs/heads/', '', ref)
|
short_ref = re.sub(r'^refs/heads/', '', ref)
|
||||||
subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
|
subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,10 @@ def ready_payload(signatories: List[Dict[str, Any]],
|
|||||||
|
|
||||||
@api_key_only_webhook_view('HelloSign')
|
@api_key_only_webhook_view('HelloSign')
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_hellosign_webhook(request, user_profile,
|
def api_hellosign_webhook(request: HttpRequest, user_profile: UserProfile,
|
||||||
payload=REQ(argument_type='body'),
|
payload: Dict[str, Dict[str, Any]]=REQ(argument_type='body'),
|
||||||
stream=REQ(default='hellosign'),
|
stream: str=REQ(default='hellosign'),
|
||||||
topic=REQ(default=None)):
|
topic: str=REQ(default=None)) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, Dict[str, Dict[str, Any]], str, str) -> HttpResponse
|
|
||||||
model_payload = ready_payload(payload['signature_request']['signatures'], payload)
|
model_payload = ready_payload(payload['signature_request']['signatures'], payload)
|
||||||
body = format_body(payload['signature_request']['signatures'], model_payload)
|
body = format_body(payload['signature_request']['signatures'], model_payload)
|
||||||
topic = topic or model_payload['contract_title']
|
topic = topic or model_payload['contract_title']
|
||||||
|
|||||||
@@ -114,9 +114,10 @@ def send_formated_pagerduty(user_profile: UserProfile,
|
|||||||
|
|
||||||
@api_key_only_webhook_view('PagerDuty')
|
@api_key_only_webhook_view('PagerDuty')
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_pagerduty_webhook(request, user_profile, payload=REQ(argument_type='body'),
|
def api_pagerduty_webhook(request: HttpRequest, user_profile: UserProfile,
|
||||||
stream=REQ(default='pagerduty'), topic=REQ(default=None)):
|
payload: Dict[str, Iterable[Dict[str, Any]]]=REQ(argument_type='body'),
|
||||||
# type: (HttpRequest, UserProfile, Dict[str, Iterable[Dict[str, Any]]], Text, Optional[Text]) -> HttpResponse
|
stream: Text=REQ(default='pagerduty'),
|
||||||
|
topic: Optional[Text]=REQ(default=None)) -> HttpResponse:
|
||||||
for message in payload['messages']:
|
for message in payload['messages']:
|
||||||
message_type = message['type']
|
message_type = message['type']
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,9 @@ def get_body_for_down_event(event: Dict[str, Any]) -> str:
|
|||||||
|
|
||||||
@api_key_only_webhook_view('Updown')
|
@api_key_only_webhook_view('Updown')
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def api_updown_webhook(request, user_profile,
|
def api_updown_webhook(request: HttpRequest, user_profile: UserProfile,
|
||||||
payload=REQ(argument_type='body'),
|
payload: List[Dict[str, Any]]=REQ(argument_type='body'),
|
||||||
stream=REQ(default='updown')):
|
stream: str=REQ(default='updown')) -> HttpResponse:
|
||||||
# type: (HttpRequest, UserProfile, List[Dict[str, Any]], str) -> HttpResponse
|
|
||||||
for event in payload:
|
for event in payload:
|
||||||
send_message_for_event(event, user_profile, request.client, stream)
|
send_message_for_event(event, user_profile, request.client, stream)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|||||||
Reference in New Issue
Block a user