mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
python: Fix misuse of Optional types for optional parameters.
There seems to have been a confusion between two different uses of the word “optional”: • An optional parameter may be omitted and replaced with a default value. • An Optional type has None as a possible value. Sometimes an optional parameter has a default value of None, or None is otherwise a meaningful value to provide, in which case it makes sense for the optional parameter to have an Optional type. But in other cases, optional parameters should not have Optional type. Fix them. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
7229088b6c
commit
69c0959f34
@@ -34,7 +34,7 @@ class UnknownEventType(Exception):
|
||||
pass
|
||||
|
||||
def get_opened_or_update_pull_request_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
pull_request = payload['pull_request']
|
||||
action = payload['action']
|
||||
if action == 'synchronize':
|
||||
@@ -56,7 +56,7 @@ def get_opened_or_update_pull_request_body(payload: Dict[str, Any],
|
||||
)
|
||||
|
||||
def get_assigned_or_unassigned_pull_request_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
pull_request = payload['pull_request']
|
||||
assignee = pull_request.get('assignee')
|
||||
if assignee is not None:
|
||||
@@ -74,7 +74,7 @@ def get_assigned_or_unassigned_pull_request_body(payload: Dict[str, Any],
|
||||
return base_message
|
||||
|
||||
def get_closed_pull_request_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
pull_request = payload['pull_request']
|
||||
action = 'merged' if pull_request['merged'] else 'closed without merge'
|
||||
return get_pull_request_event_message(
|
||||
@@ -110,7 +110,7 @@ def get_member_body(payload: Dict[str, Any]) -> str:
|
||||
)
|
||||
|
||||
def get_issue_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
action = payload['action']
|
||||
issue = payload['issue']
|
||||
assignee = issue['assignee']
|
||||
@@ -125,7 +125,7 @@ def get_issue_body(payload: Dict[str, Any],
|
||||
)
|
||||
|
||||
def get_issue_comment_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
action = payload['action']
|
||||
comment = payload['comment']
|
||||
issue = payload['issue']
|
||||
@@ -305,7 +305,7 @@ def get_status_body(payload: Dict[str, Any]) -> str:
|
||||
)
|
||||
|
||||
def get_pull_request_ready_for_review_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
|
||||
message = "**{sender}** has marked [PR #{pr_number}]({pr_url}) as ready for review."
|
||||
return message.format(
|
||||
@@ -315,7 +315,7 @@ def get_pull_request_ready_for_review_body(payload: Dict[str, Any],
|
||||
)
|
||||
|
||||
def get_pull_request_review_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
title = "for #{} {}".format(
|
||||
payload['pull_request']['number'],
|
||||
payload['pull_request']['title'],
|
||||
@@ -329,7 +329,7 @@ def get_pull_request_review_body(payload: Dict[str, Any],
|
||||
)
|
||||
|
||||
def get_pull_request_review_comment_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
action = payload['action']
|
||||
message = None
|
||||
if action == 'created':
|
||||
@@ -350,7 +350,7 @@ def get_pull_request_review_comment_body(payload: Dict[str, Any],
|
||||
)
|
||||
|
||||
def get_pull_request_review_requested_body(payload: Dict[str, Any],
|
||||
include_title: Optional[bool]=False) -> str:
|
||||
include_title: bool=False) -> str:
|
||||
requested_reviewer = [payload['requested_reviewer']] if 'requested_reviewer' in payload else []
|
||||
requested_reviewers = (payload['pull_request']['requested_reviewers'] or requested_reviewer)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user