Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
python: Fix misuse of Optional types for optional parameters.
Anders Kaseorg69c0959f345d
diff --git a/analytics/tests/test_views.py b/analytics/tests/test_views.pyindex 2ec434b456b..f43bc4878e1 100644--- a/analytics/tests/test_views.py+++ b/analytics/tests/test_views.py@@ -427,7 +427,7 @@ class TestSupportEndpoint(ZulipTestCase):'scrub-realm-button">','data-string-id="lear"'], result)- def check_preregistration_user_query_result(result: HttpResponse, email: str, invite: Optional[bool]=False) -> None:+ def check_preregistration_user_query_result(result: HttpResponse, email: str, invite: bool=False) -> None:self.assert_in_success_response(['<span class="label">preregistration user</span>\n',f'<b>Email</b>: {email}',], result)diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 2eabbcabc34..20f3f5f01de 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -275,7 +275,7 @@ def update_or_create_stripe_customer(user: UserProfile, stripe_token: Optional[sdef compute_plan_parameters(automanage_licenses: bool, billing_schedule: int,discount: Optional[Decimal],- free_trial: Optional[bool]=False) -> Tuple[datetime, datetime, datetime, int]:+ free_trial: bool=False) -> Tuple[datetime, datetime, datetime, int]:# Everything in Stripe is stored as timestamps with 1 second resolution,# so standardize on 1 second resolution.# TODO talk about leapseconds?diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex cfd95869175..77059b44a3e 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -1527,7 +1527,7 @@ class RequiresBillingAccessTest(ZulipTestCase):hamlet.save(update_fields=["is_billing_admin"])def verify_non_admins_blocked_from_endpoint(- self, url: str, request_data: Optional[Dict[str, Any]]={}) -> None:+ self, url: str, request_data: Dict[str, Any]={}) -> None:cordelia = self.example_user('cordelia')self.login_user(cordelia)response = self.client_post(url, request_data)diff --git a/tools/test-locked-requirements b/tools/test-locked-requirementsindex 23902646607..152aab1bf3a 100755--- a/tools/test-locked-requirements+++ b/tools/test-locked-requirements@@ -8,7 +8,7 @@ import shutilimport subprocessimport sysimport tempfile-from typing import List, Optional+from typing import Listimport ujson@@ -49,7 +49,7 @@ def test_locked_requirements(tmp_dir: str) -> bool:return same-def get_requirements_hash(tmp_dir: str, use_test_lock_files: Optional[bool] = False) -> str:+def get_requirements_hash(tmp_dir: str, use_test_lock_files: bool = False) -> str:sha1 = hashlib.sha1()reqs_files = sorted(glob.glob(os.path.join(REQS_DIR, "*.in")))lock_files_path = REQS_DIRdiff --git a/zerver/decorator.py b/zerver/decorator.pyindex ae4a62d231b..f26888b0eed 100644--- a/zerver/decorator.py+++ b/zerver/decorator.py@@ -269,7 +269,7 @@ def access_user_by_api_key(request: HttpRequest, api_key: str, email: Optional[sdef log_exception_to_webhook_logger(request: HttpRequest, user_profile: UserProfile,request_body: Optional[str]=None,- unexpected_event: Optional[bool]=False,+ unexpected_event: bool=False,) -> None:if request_body is not None:payload = request_body@@ -328,7 +328,7 @@ def full_webhook_client_name(raw_client_name: Optional[str]=None) -> Optional[st# Use this for webhook views that don't get an email passed in.def api_key_only_webhook_view(webhook_client_name: str,- notify_bot_owner_on_invalid_json: Optional[bool]=True,+ notify_bot_owner_on_invalid_json: bool=True,) -> Callable[[ViewFuncT], ViewFuncT]:# TODO The typing here could be improved by using the Extended Callable types:# https://mypy.readthedocs.io/en/latest/kinds_of_types.html#extended-callable-typesdiff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 6bce33df3a1..ed197d47b6d 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -1030,7 +1030,7 @@ def render_incoming_message(message: Message,user_ids: Set[int],realm: Realm,mention_data: Optional[bugdown.MentionData]=None,- email_gateway: Optional[bool]=False) -> str:+ email_gateway: bool=False) -> str:realm_alert_words_automaton = get_alert_word_automaton(realm)try:rendered_content = render_markdown(@@ -1343,7 +1343,7 @@ def do_schedule_messages(messages: Sequence[Mapping[str, Any]]) -> List[int]:def do_send_messages(messages_maybe_none: Sequence[Optional[MutableMapping[str, Any]]],- email_gateway: Optional[bool]=False,+ email_gateway: bool=False,mark_as_read: List[int]=[]) -> List[int]:"""Seehttps://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html@@ -2456,7 +2456,7 @@ def internal_send_stream_message(stream: Stream,topic: str,content: str,- email_gateway: Optional[bool]=False) -> Optional[int]:+ email_gateway: bool=False) -> Optional[int]:message = internal_prep_stream_message(realm, sender, stream,@@ -5020,7 +5020,7 @@ def check_invite_limit(realm: Realm, num_invitees: int) -> None:def do_invite_users(user_profile: UserProfile,invitee_emails: SizedTextIterable,streams: Iterable[Stream],- invite_as: Optional[int]=PreregistrationUser.INVITE_AS['MEMBER']) -> None:+ invite_as: int=PreregistrationUser.INVITE_AS['MEMBER']) -> None:check_invite_limit(user_profile.realm, len(invitee_emails))@@ -5142,7 +5142,7 @@ def do_get_user_invites(user_profile: UserProfile) -> List[Dict[str, Any]]:return invitesdef do_create_multiuse_invite_link(referred_by: UserProfile, invited_as: int,- streams: Optional[List[Stream]]=[]) -> str:+ streams: List[Stream]=[]) -> str:realm = referred_by.realminvite = MultiuseInvite.objects.create(realm=realm, referred_by=referred_by)if streams:diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.pyindex a0bcdc85ccb..5bb48f9a904 100644--- a/zerver/lib/bugdown/__init__.py+++ b/zerver/lib/bugdown/__init__.py@@ -232,7 +232,7 @@ def rewrite_local_links_to_relative(db_data: Optional[DbData], link: str) -> strdef url_embed_preview_enabled(message: Optional[Message]=None,realm: Optional[Realm]=None,- no_previews: Optional[bool]=False) -> bool:+ no_previews: bool=False) -> bool:if not settings.INLINE_URL_EMBED_PREVIEW:return False@@ -253,7 +253,7 @@ def url_embed_preview_enabled(message: Optional[Message]=None,def image_preview_enabled(message: Optional[Message]=None,realm: Optional[Realm]=None,- no_previews: Optional[bool]=False) -> bool:+ no_previews: bool=False) -> bool:if not settings.INLINE_IMAGE_PREVIEW:return False@@ -558,7 +558,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):class_attr: str="message_inline_image",data_id: Optional[str]=None,insertion_index: Optional[int]=None,- already_thumbnailed: Optional[bool]=False,+ already_thumbnailed: bool=False,) -> None:desc = desc if desc is not None else ""@@ -2260,11 +2260,11 @@ def do_convert(content: str,realm_alert_words_automaton: Optional[ahocorasick.Automaton] = None,message: Optional[Message]=None,message_realm: Optional[Realm]=None,- sent_by_bot: Optional[bool]=False,- translate_emoticons: Optional[bool]=False,+ sent_by_bot: bool=False,+ translate_emoticons: bool=False,mention_data: Optional[MentionData]=None,- email_gateway: Optional[bool]=False,- no_previews: Optional[bool]=False) -> str:+ email_gateway: bool=False,+ no_previews: bool=False) -> str:"""Convert Markdown to HTML, with Zulip-specific settings and hacks."""# This logic is a bit convoluted, but the overall goal is to support a range of use cases:# * Nothing is passed in other than content -> just run default options (e.g. for docs)@@ -2405,11 +2405,11 @@ def convert(content: str,realm_alert_words_automaton: Optional[ahocorasick.Automaton] = None,message: Optional[Message]=None,message_realm: Optional[Realm]=None,- sent_by_bot: Optional[bool]=False,- translate_emoticons: Optional[bool]=False,+ sent_by_bot: bool=False,+ translate_emoticons: bool=False,mention_data: Optional[MentionData]=None,- email_gateway: Optional[bool]=False,- no_previews: Optional[bool]=False) -> str:+ email_gateway: bool=False,+ no_previews: bool=False) -> str:bugdown_stats_start()ret = do_convert(content, realm_alert_words_automaton,message, message_realm, sent_by_bot,diff --git a/zerver/lib/bugdown/fenced_code.py b/zerver/lib/bugdown/fenced_code.pyindex fe35b6a5f6c..226d3b8be04 100644--- a/zerver/lib/bugdown/fenced_code.py+++ b/zerver/lib/bugdown/fenced_code.py@@ -158,7 +158,7 @@ class BaseHandler:def generic_handler(processor: Any, output: MutableSequence[str],fence: str, lang: str,- run_content_validators: Optional[bool]=False,+ run_content_validators: bool=False,default_language: Optional[str]=None) -> BaseHandler:if lang in ('quote', 'quoted'):return QuoteHandler(processor, output, fence, default_language)@@ -168,7 +168,7 @@ def generic_handler(processor: Any, output: MutableSequence[str],return CodeHandler(processor, output, fence, lang, run_content_validators)def check_for_new_fence(processor: Any, output: MutableSequence[str], line: str,- run_content_validators: Optional[bool]=False,+ run_content_validators: bool=False,default_language: Optional[str]=None) -> None:m = FENCE_RE.match(line)if m:@@ -183,7 +183,7 @@ def check_for_new_fence(processor: Any, output: MutableSequence[str], line: str,class OuterHandler(BaseHandler):def __init__(self, processor: Any, output: MutableSequence[str],- run_content_validators: Optional[bool]=False,+ run_content_validators: bool=False,default_language: Optional[str]=None) -> None:self.output = outputself.processor = processor@@ -199,7 +199,7 @@ class OuterHandler(BaseHandler):class CodeHandler(BaseHandler):def __init__(self, processor: Any, output: MutableSequence[str],- fence: str, lang: str, run_content_validators: Optional[bool]=False) -> None:+ fence: str, lang: str, run_content_validators: bool=False) -> None:self.processor = processorself.output = outputself.fence = fence@@ -278,7 +278,7 @@ class TexHandler(BaseHandler):class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):- def __init__(self, md: markdown.Markdown, run_content_validators: Optional[bool]=False) -> None:+ def __init__(self, md: markdown.Markdown, run_content_validators: bool=False) -> None:markdown.preprocessors.Preprocessor.__init__(self, md)self.checked_for_codehilite = Falsediff --git a/zerver/lib/ccache.py b/zerver/lib/ccache.pyindex a2f159c3cf3..2160f1f03d0 100644--- a/zerver/lib/ccache.py+++ b/zerver/lib/ccache.py@@ -100,7 +100,7 @@ def der_encode_octet_string(val: bytes) -> bytes:raise TypeError("bytes")return der_encode_tlv(0x04, val)-def der_encode_sequence(tlvs: List[Optional[bytes]], tagged: Optional[bool]=True) -> bytes:+def der_encode_sequence(tlvs: List[Optional[bytes]], tagged: bool=True) -> bytes:body = []for i, tlv in enumerate(tlvs):# Missing optional elements represented as None.diff --git a/zerver/lib/create_user.py b/zerver/lib/create_user.pyindex dc8e16a7718..28764886bf5 100644--- a/zerver/lib/create_user.py+++ b/zerver/lib/create_user.py@@ -65,7 +65,7 @@ def create_user_profile(realm: Realm, email: str, password: Optional[str],short_name: str, bot_owner: Optional[UserProfile],is_mirror_dummy: bool, tos_version: Optional[str],timezone: Optional[str],- tutorial_status: Optional[str] = UserProfile.TUTORIAL_WAITING,+ tutorial_status: str = UserProfile.TUTORIAL_WAITING,enter_sends: bool = False) -> UserProfile:now = timezone_now()email = UserManager.normalize_email(email)diff --git a/zerver/lib/error_notify.py b/zerver/lib/error_notify.pyindex 21b8f099600..60512a4e347 100644--- a/zerver/lib/error_notify.py+++ b/zerver/lib/error_notify.py@@ -1,6 +1,6 @@# System documented in https://zulip.readthedocs.io/en/latest/subsystems/logging.htmlfrom collections import defaultdict-from typing import Any, Dict, Optional+from typing import Any, Dictfrom django.conf import settingsfrom django.core.mail import mail_admins@@ -87,7 +87,7 @@ def zulip_browser_error(report: Dict[str, Any]) -> None:body,)-def notify_server_error(report: Dict[str, Any], skip_error_zulip: Optional[bool]=False) -> None:+def notify_server_error(report: Dict[str, Any], skip_error_zulip: bool=False) -> None:report = defaultdict(lambda: None, report)email_server_error(report)if settings.ERROR_BOT and not skip_error_zulip:diff --git a/zerver/lib/message.py b/zerver/lib/message.pyindex 5be36afc371..f8ebc82a345 100644--- a/zerver/lib/message.py+++ b/zerver/lib/message.py@@ -660,7 +660,7 @@ def render_markdown(message: Message,realm_alert_words_automaton: Optional[ahocorasick.Automaton]=None,user_ids: Optional[Set[int]]=None,mention_data: Optional[bugdown.MentionData]=None,- email_gateway: Optional[bool]=False) -> str:+ email_gateway: bool=False) -> str:'''This is basically just a wrapper for do_render_markdown.'''@@ -699,7 +699,7 @@ def do_render_markdown(message: Message,translate_emoticons: bool,realm_alert_words_automaton: Optional[ahocorasick.Automaton]=None,mention_data: Optional[bugdown.MentionData]=None,- email_gateway: Optional[bool]=False) -> str:+ email_gateway: bool=False) -> str:"""Return HTML for given markdown. Bugdown may add properties to themessage object such as `mentions_user_ids`, `mentions_user_group_ids`, and`mentions_wildcard`. These are only on this Django object and are notdiff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex de686cd6dea..0cde5be1b23 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -403,12 +403,12 @@ class ZulipTestCase(TestCase):def submit_reg_form_for_user(self, email: str, password: str,- realm_name: Optional[str]="Zulip Test",- realm_subdomain: Optional[str]="zuliptest",- from_confirmation: Optional[str]='', full_name: Optional[str]=None,- timezone: Optional[str]='', realm_in_root_domain: Optional[str]=None,- default_stream_groups: Optional[List[str]]=[],- source_realm: Optional[str]='',+ realm_name: str="Zulip Test",+ realm_subdomain: str="zuliptest",+ from_confirmation: str='', full_name: Optional[str]=None,+ timezone: str='', realm_in_root_domain: Optional[str]=None,+ default_stream_groups: List[str]=[],+ source_realm: str='',key: Optional[str]=None, **kwargs: Any) -> HttpResponse:"""Stage two of the two-step registration process.@@ -668,7 +668,7 @@ class ZulipTestCase(TestCase):return open(fn).read()def make_stream(self, stream_name: str, realm: Optional[Realm]=None,- invite_only: Optional[bool]=False,+ invite_only: bool=False,history_public_to_subscribers: Optional[bool]=None) -> Stream:if realm is None:realm = get_realm('zulip')@@ -918,7 +918,7 @@ class WebhookTestCase(ZulipTestCase):return msgdef send_and_test_private_message(self, fixture_name: str, expected_topic: str=None,- expected_message: str=None, content_type: str="application/json",+ expected_message: str=None, content_type: Optional[str]="application/json",**kwargs: Any) -> Message:payload = self.get_body(fixture_name)if content_type is not None:diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.pyindex d1d7c9ef123..b9984e7c14a 100644--- a/zerver/lib/test_helpers.py+++ b/zerver/lib/test_helpers.py@@ -148,7 +148,7 @@ def simulated_empty_cache() -> Generator[cache.cache_get_many = old_get_many@contextmanager-def queries_captured(include_savepoints: Optional[bool]=False) -> Generator[+def queries_captured(include_savepoints: bool=False) -> Generator[List[Dict[str, Union[str, bytes]]], None, None]:'''Allow a user to capture just the queries executed duringdiff --git a/zerver/lib/test_runner.py b/zerver/lib/test_runner.pyindex faa2527876f..fa00625afac 100644--- a/zerver/lib/test_runner.py+++ b/zerver/lib/test_runner.py@@ -313,7 +313,7 @@ def init_worker(counter: Synchronized) -> None:print("*** Upload directory not found.")class TestSuite(unittest.TestSuite):- def run(self, result: TestResult, debug: Optional[bool]=False) -> TestResult:+ def run(self, result: TestResult, debug: bool=False) -> TestResult:"""This function mostly contains the code fromunittest.TestSuite.run. The need to override this functiondiff --git a/zerver/lib/url_preview/oembed.py b/zerver/lib/url_preview/oembed.pyindex b9451806b19..1a9ecaea8c9 100644--- a/zerver/lib/url_preview/oembed.py+++ b/zerver/lib/url_preview/oembed.py@@ -5,8 +5,8 @@ from pyoembed import PyOembedException, oEmbeddef get_oembed_data(url: str,- maxwidth: Optional[int]=640,- maxheight: Optional[int]=480) -> Optional[Dict[str, Any]]:+ maxwidth: int=640,+ maxheight: int=480) -> Optional[Dict[str, Any]]:try:data = oEmbed(url, maxwidth=maxwidth, maxheight=maxheight)except (PyOembedException, json.decoder.JSONDecodeError):diff --git a/zerver/lib/url_preview/preview.py b/zerver/lib/url_preview/preview.pyindex f7647441008..5c1b40eea0d 100644--- a/zerver/lib/url_preview/preview.py+++ b/zerver/lib/url_preview/preview.py@@ -74,8 +74,8 @@ def catch_network_errors(func: Callable[..., Any]) -> Callable[..., Any]:@catch_network_errors@cache_with_key(preview_url_cache_key, cache_name=CACHE_NAME, with_statsd_key="urlpreview_data")def get_link_embed_data(url: str,- maxwidth: Optional[int]=640,- maxheight: Optional[int]=480) -> Optional[Dict[str, Any]]:+ maxwidth: int=640,+ maxheight: int=480) -> Optional[Dict[str, Any]]:if not is_link(url):return None@@ -103,5 +103,5 @@ def get_link_embed_data(url: str,return data@get_cache_with_key(preview_url_cache_key, cache_name=CACHE_NAME)-def link_embed_data_from_cache(url: str, maxwidth: Optional[int]=640, maxheight: Optional[int]=480) -> Any:+def link_embed_data_from_cache(url: str, maxwidth: int=640, maxheight: int=480) -> Any:returndiff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.pyindex 3edd2ca0d2b..aad19a9ff08 100644--- a/zerver/lib/webhooks/common.py+++ b/zerver/lib/webhooks/common.py@@ -61,7 +61,7 @@ def check_send_webhook_message(request: HttpRequest, user_profile: UserProfile,topic: str, body: str, stream: Optional[str]=REQ(default=None),user_specified_topic: Optional[str]=REQ("topic", default=None),- unquote_url_parameters: Optional[bool]=False,+ unquote_url_parameters: bool=False,) -> None:if stream is None:@@ -115,7 +115,7 @@ def standardize_headers(input_headers: Union[None, Dict[str, Any]]) -> Dict[str,def validate_extract_webhook_http_header(request: HttpRequest, header: str,integration_name: str,- fatal: Optional[bool]=True) -> Optional[str]:+ fatal: bool=True) -> Optional[str]:extracted_header = request.META.get(DJANGO_HTTP_PREFIX + header)if extracted_header is None and fatal:message_body = MISSING_EVENT_HEADER_MESSAGE.format(diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.pyindex 84b548e888f..997bda9c947 100644--- a/zerver/lib/webhooks/git.py+++ b/zerver/lib/webhooks/git.py@@ -57,8 +57,8 @@ RELEASE_MESSAGE_TEMPLATE = "{user_name} {action} release [{release_name}]({url})def get_push_commits_event_message(user_name: str, compare_url: Optional[str],branch_name: str, commits_data: List[Dict[str, Any]],- is_truncated: Optional[bool]=False,- deleted: Optional[bool]=False) -> str:+ is_truncated: bool=False,+ deleted: bool=False) -> str:if not commits_data and deleted:return PUSH_DELETE_BRANCH_MESSAGE_TEMPLATE.format(user_name=user_name,@@ -135,7 +135,7 @@ def get_pull_request_event_message(user_name: str, action: str, url: str, numbertarget_branch: Optional[str]=None, base_branch: Optional[str]=None,message: Optional[str]=None, assignee: Optional[str]=None,assignees: Optional[List[Dict[str, Any]]]=None,- type: Optional[str]='PR', title: Optional[str]=None) -> str:+ type: str='PR', title: Optional[str]=None) -> str:kwargs = {'user_name': user_name,'action': action,@@ -220,7 +220,7 @@ def get_issue_event_message(user_name: str,def get_push_tag_event_message(user_name: str,tag_name: str,tag_url: Optional[str]=None,- action: Optional[str]='pushed') -> str:+ action: str='pushed') -> str:if tag_url:tag_part = TAG_WITH_URL_TEMPLATE.format(tag_name=tag_name, tag_url=tag_url)else:@@ -257,7 +257,7 @@ def get_commits_comment_action_message(user_name: str,return content-def get_commits_content(commits_data: List[Dict[str, Any]], is_truncated: Optional[bool]=False) -> str:+def get_commits_content(commits_data: List[Dict[str, Any]], is_truncated: bool=False) -> str:commits_content = ''for commit in commits_data[:COMMITS_LIMIT]:commits_content += COMMIT_ROW_TEMPLATE.format(diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.pyindex 4dc85f88b71..f5f561a7a9a 100644--- a/zerver/openapi/markdown_extension.py+++ b/zerver/openapi/markdown_extension.py@@ -97,7 +97,7 @@ def extract_code_example(source: List[str], snippet: List[Any],source = source[end + 1:]return extract_code_example(source, snippet, example_regex)-def render_python_code_example(function: str, admin_config: Optional[bool]=False,+def render_python_code_example(function: str, admin_config: bool=False,**kwargs: Any) -> List[str]:method = zerver.openapi.python_examples.TEST_FUNCTIONS[function]function_source_lines = inspect.getsourcelines(method)[0]@@ -124,7 +124,7 @@ def render_python_code_example(function: str, admin_config: Optional[bool]=Falsereturn code_example-def render_javascript_code_example(function: str, admin_config: Optional[bool]=False,+def render_javascript_code_example(function: str, admin_config: bool=False,**kwargs: Any) -> List[str]:function_source_lines = []with open('zerver/openapi/javascript_examples.js') as f:diff --git a/zerver/openapi/openapi.py b/zerver/openapi/openapi.pyindex c1c03152d88..67ae4686380 100644--- a/zerver/openapi/openapi.py+++ b/zerver/openapi/openapi.py@@ -77,11 +77,9 @@ def get_schema(endpoint: str, method: str, response: str) -> Dict[str, Any]:return schemadef get_openapi_fixture(endpoint: str, method: str,- response: Optional[str]='200') -> Dict[str, Any]:+ response: str='200') -> Dict[str, Any]:"""Fetch a fixture from the full spec object."""- if response is None:- response = '200'return (get_schema(endpoint, method, response)['example'])def get_openapi_description(endpoint: str, method: str) -> str:diff --git a/zerver/templatetags/app_filters.py b/zerver/templatetags/app_filters.pyindex 2c23d10f175..00b2503a257 100644--- a/zerver/templatetags/app_filters.py+++ b/zerver/templatetags/app_filters.py@@ -76,7 +76,7 @@ docs_without_macros = [@register.filter(name='render_markdown_path', is_safe=True)def render_markdown_path(markdown_file_path: str,context: Optional[Dict[Any, Any]]=None,- pure_markdown: Optional[bool]=False) -> str:+ pure_markdown: bool=False) -> str:"""Given a path to a markdown file, return the rendered html.Note that this assumes that any HTML in the markdown file isdiff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.pyindex b8311d82598..85618a87394 100644--- a/zerver/tests/test_bugdown.py+++ b/zerver/tests/test_bugdown.py@@ -1490,7 +1490,7 @@ class BugdownTest(ZulipTestCase):self.assertEqual(msg.mentions_user_ids, set())def test_possible_mentions(self) -> None:- def assert_mentions(content: str, names: Set[str], has_wildcards: Optional[bool]=False) -> None:+ def assert_mentions(content: str, names: Set[str], has_wildcards: bool=False) -> None:self.assertEqual(possible_mentions(content), (names, has_wildcards))assert_mentions('', set())diff --git a/zerver/views/invite.py b/zerver/views/invite.pyindex de93ac5d989..6d024fa67ca 100644--- a/zerver/views/invite.py+++ b/zerver/views/invite.py@@ -1,5 +1,5 @@import re-from typing import List, Optional, Set+from typing import List, Setfrom django.http import HttpRequest, HttpResponsefrom django.utils.translation import ugettext as _@@ -25,7 +25,7 @@ from zerver.models import MultiuseInvite, PreregistrationUser, Stream, UserProfi@has_request_variablesdef invite_users_backend(request: HttpRequest, user_profile: UserProfile,invitee_emails_raw: str=REQ("invitee_emails"),- invite_as: Optional[int]=REQ(+ invite_as: int=REQ(validator=check_int, default=PreregistrationUser.INVITE_AS['MEMBER']),stream_ids: List[int]=REQ(validator=check_list(check_int)),) -> HttpResponse:diff --git a/zerver/views/messages.py b/zerver/views/messages.pyindex 6ad5a5b34b6..db20d804371 100644--- a/zerver/views/messages.py+++ b/zerver/views/messages.py@@ -1369,8 +1369,8 @@ def send_message_backend(request: HttpRequest, user_profile: UserProfile,documentation_pending=True),queue_id: Optional[str]=REQ(default=None,documentation_pending=True),- delivery_type: Optional[str]=REQ('delivery_type', default='send_now',- documentation_pending=True),+ delivery_type: str=REQ('delivery_type', default='send_now',+ documentation_pending=True),defer_until: Optional[str]=REQ('deliver_at', default=None,documentation_pending=True),tz_guess: Optional[str]=REQ('tz_guess', default=None,diff --git a/zerver/views/registration.py b/zerver/views/registration.pyindex 290acf4cb46..47fdc06e206 100644--- a/zerver/views/registration.py+++ b/zerver/views/registration.py@@ -530,7 +530,7 @@ def create_realm(request: HttpRequest, creation_key: Optional[str]=None) -> Httpcontext={'form': form, 'current_url': request.get_full_path},)-def accounts_home(request: HttpRequest, multiuse_object_key: Optional[str]="",+def accounts_home(request: HttpRequest, multiuse_object_key: str="",multiuse_object: Optional[MultiuseInvite]=None) -> HttpResponse:try:realm = get_realm(get_subdomain(request))diff --git a/zerver/views/users.py b/zerver/views/users.pyindex fd5e926f3a1..b720b77fa53 100644--- a/zerver/views/users.py+++ b/zerver/views/users.py@@ -122,7 +122,7 @@ def reactivate_user_backend(request: HttpRequest, user_profile: UserProfile,@has_request_variablesdef update_user_backend(request: HttpRequest, user_profile: UserProfile, user_id: int,- full_name: Optional[str]=REQ(default="", validator=check_string),+ full_name: Optional[str]=REQ(default=None, validator=check_string),role: Optional[int]=REQ(default=None, validator=check_int_in(UserProfile.ROLE_TYPES)),profile_data: Optional[List[Dict[str, Union[int, str, List[int]]]]]=diff --git a/zerver/webhooks/beanstalk/view.py b/zerver/webhooks/beanstalk/view.pyindex 2e23e457882..b1714aa5b7b 100644--- a/zerver/webhooks/beanstalk/view.py+++ b/zerver/webhooks/beanstalk/view.py@@ -19,7 +19,7 @@ from zerver.models import UserProfiledef build_message_from_gitlog(user_profile: UserProfile, name: str, ref: str,commits: List[Dict[str, str]], before: str, after: str,url: str, pusher: str, forced: Optional[str]=None,- created: Optional[str]=None, deleted: Optional[bool]=False,+ created: Optional[str]=None, deleted: bool=False,) -> Tuple[str, str]:short_ref = re.sub(r'^refs/heads/', '', ref)subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.pyindex 35bae5d0bac..f69cb21d88c 100644--- a/zerver/webhooks/bitbucket2/view.py+++ b/zerver/webhooks/bitbucket2/view.py@@ -254,12 +254,12 @@ def get_commit_status_changed_body(payload: Dict[str, Any]) -> str:)def get_issue_commented_body(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:action = '[commented]({}) on'.format(payload['comment']['links']['html']['href'])return get_issue_action_body(payload, action, include_title)def get_issue_action_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:issue = payload['issue']assignee = Nonemessage = None@@ -279,7 +279,7 @@ def get_issue_action_body(payload: Dict[str, Any], action: str,)def get_pull_request_action_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:pull_request = payload['pullrequest']return get_pull_request_event_message(get_user_username(payload),@@ -290,7 +290,7 @@ def get_pull_request_action_body(payload: Dict[str, Any], action: str,)def get_pull_request_created_or_updated_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:pull_request = payload['pullrequest']assignee = Noneif pull_request.get('reviewers'):@@ -314,21 +314,21 @@ def get_pull_request_created_or_updated_body(payload: Dict[str, Any], action: stdef get_pull_request_comment_created_action_body(payload: Dict[str, Any],- include_title: Optional[bool]=False,+ include_title: bool=False,) -> str:action = '[commented]({})'.format(payload['comment']['links']['html']['href'])return get_pull_request_comment_action_body(payload, action, include_title)def get_pull_request_deleted_or_updated_comment_action_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False,+ include_title: bool=False,) -> str:action = "{} a [comment]({})".format(action, payload['comment']['links']['html']['href'])return get_pull_request_comment_action_body(payload, action, include_title)def get_pull_request_comment_action_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False,+ include_title: bool=False,) -> str:action += ' on'return get_pull_request_event_message(@@ -343,7 +343,7 @@ def get_pull_request_comment_action_body(def get_push_tag_body(payload: Dict[str, Any], change: Dict[str, Any]) -> str:if change.get('new'):tag = change['new']- action: Optional[str] = 'pushed'+ action = 'pushed'elif change.get('old'):tag = change['old']action = 'removed'diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.pyindex cb6bae92d73..a84f2b534b0 100644--- a/zerver/webhooks/bitbucket3/view.py+++ b/zerver/webhooks/bitbucket3/view.py@@ -290,7 +290,7 @@ def get_pr_reassigned_body(payload: Dict[str, Any], include_title: Optional[bool)def pr_handler(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> List[Dict[str, str]]:+ include_title: bool=False) -> List[Dict[str, str]]:pr = payload["pullRequest"]subject = get_pr_subject(pr["toRef"]["repository"]["name"], type="PR", id=pr["id"],title=pr["title"])@@ -306,7 +306,7 @@ def pr_handler(payload: Dict[str, Any], action: str,return [{"subject": subject, "body": body}]def pr_comment_handler(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> List[Dict[str, str]]:+ include_title: bool=False) -> List[Dict[str, str]]:pr = payload["pullRequest"]subject = get_pr_subject(pr["toRef"]["repository"]["name"], type="PR", id=pr["id"],title=pr["title"])diff --git a/zerver/webhooks/gitea/view.py b/zerver/webhooks/gitea/view.pyindex c001f4620a1..06abfdc82bc 100644--- a/zerver/webhooks/gitea/view.py+++ b/zerver/webhooks/gitea/view.py@@ -14,7 +14,7 @@ from zerver.webhooks.gogs.view import gogs_webhook_mainfixture_to_headers = get_http_headers_from_filename("HTTP_X_GITEA_EVENT")def format_pull_request_event(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:assignee = payload['pull_request']['assignee']data = {'user_name': payload['pull_request']['user']['username'],diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.pyindex 1e677e0c679..2c80fe859d6 100644--- a/zerver/webhooks/github/view.py+++ b/zerver/webhooks/github/view.py@@ -34,7 +34,7 @@ class UnknownEventType(Exception):passdef 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_messagedef 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 = Noneif 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)diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.pyindex 6e10e2e19c0..adf8feb5628 100644--- a/zerver/webhooks/gitlab/view.py+++ b/zerver/webhooks/gitlab/view.py@@ -77,7 +77,7 @@ def get_tag_push_event_body(payload: Dict[str, Any]) -> str:)def get_issue_created_event_body(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:description = payload['object_attributes'].get('description')# Filter out multiline hidden commentsif description is not None:@@ -96,7 +96,7 @@ def get_issue_created_event_body(payload: Dict[str, Any],)def get_issue_event_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:return get_issue_event_message(get_issue_user_name(payload),action,@@ -106,7 +106,7 @@ def get_issue_event_body(payload: Dict[str, Any], action: str,)def get_merge_request_updated_event_body(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:if payload['object_attributes'].get('oldrev'):return get_merge_request_event_body(payload, "added commit(s) to",@@ -119,7 +119,7 @@ def get_merge_request_updated_event_body(payload: Dict[str, Any],)def get_merge_request_event_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:pull_request = payload['object_attributes']return get_pull_request_event_message(get_issue_user_name(payload),@@ -131,7 +131,7 @@ def get_merge_request_event_body(payload: Dict[str, Any], action: str,)def get_merge_request_open_or_updated_body(payload: Dict[str, Any], action: str,- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:pull_request = payload['object_attributes']return get_pull_request_event_message(get_issue_user_name(payload),@@ -170,7 +170,7 @@ def get_commented_commit_event_body(payload: Dict[str, Any]) -> str:)def get_commented_merge_request_event_body(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:comment = payload['object_attributes']action = '[commented]({}) on'.format(comment['url'])url = '{}/merge_requests/{}'.format(@@ -189,7 +189,7 @@ def get_commented_merge_request_event_body(payload: Dict[str, Any],)def get_commented_issue_event_body(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:comment = payload['object_attributes']action = '[commented]({}) on'.format(comment['url'])url = '{}/issues/{}'.format(@@ -208,7 +208,7 @@ def get_commented_issue_event_body(payload: Dict[str, Any],)def get_commented_snippet_event_body(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:comment = payload['object_attributes']action = '[commented]({}) on'.format(comment['url'])url = '{}/snippets/{}'.format(diff --git a/zerver/webhooks/gogs/view.py b/zerver/webhooks/gogs/view.pyindex 2f4a46300ff..4832f48b593 100644--- a/zerver/webhooks/gogs/view.py+++ b/zerver/webhooks/gogs/view.py@@ -58,7 +58,7 @@ def format_new_branch_event(payload: Dict[str, Any]) -> str:return get_create_branch_event_message(**data)def format_pull_request_event(payload: Dict[str, Any],- include_title: Optional[bool]=False) -> str:+ include_title: bool=False) -> str:data = {'user_name': payload['pull_request']['user']['username'],@@ -76,7 +76,7 @@ def format_pull_request_event(payload: Dict[str, Any],return get_pull_request_event_message(**data)-def format_issues_event(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str:+def format_issues_event(payload: Dict[str, Any], include_title: bool=False) -> str:issue_nr = payload['issue']['number']assignee = payload['issue']['assignee']return get_issue_event_message(@@ -89,7 +89,7 @@ def format_issues_event(payload: Dict[str, Any], include_title: Optional[bool]=Ftitle=payload['issue']['title'] if include_title else None,)-def format_issue_comment_event(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str:+def format_issue_comment_event(payload: Dict[str, Any], include_title: bool=False) -> str:action = payload['action']comment = payload['comment']issue = payload['issue']@@ -109,7 +109,7 @@ def format_issue_comment_event(payload: Dict[str, Any], include_title: Optional[title=issue['title'] if include_title else None,)-def format_release_event(payload: Dict[str, Any], include_title: Optional[bool]=False) -> str:+def format_release_event(payload: Dict[str, Any], include_title: bool=False) -> str:data = {'user_name': payload['release']['author']['username'],'action': payload['action'],