mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
mypy: Add explicit Optional for default=None parameters in various files.
This commit is contained in:
committed by
Tim Abbott
parent
9a90c225a6
commit
090b47ed19
@@ -26,7 +26,7 @@ django.setup()
|
|||||||
from zerver.models import UserActivity
|
from zerver.models import UserActivity
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Any, Dict, Set
|
from typing import Any, Dict, Set, Optional
|
||||||
|
|
||||||
states = {
|
states = {
|
||||||
"OK": 0,
|
"OK": 0,
|
||||||
@@ -36,7 +36,7 @@ states = {
|
|||||||
} # type: Dict[str, int]
|
} # type: Dict[str, int]
|
||||||
|
|
||||||
def report(state, short_msg, too_old=None):
|
def report(state, short_msg, too_old=None):
|
||||||
# type: (str, str, Set[Any]) -> None
|
# type: (str, str, Optional[Set[Any]]) -> None
|
||||||
too_old_data = ""
|
too_old_data = ""
|
||||||
if too_old:
|
if too_old:
|
||||||
too_old_data = "\nLast call to get_message for recently out of date mirrors:\n" + "\n".join(
|
too_old_data = "\nLast call to get_message for recently out of date mirrors:\n" + "\n".join(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Callable, List, Tuple, Union
|
from typing import Callable, List, Tuple, Union, Optional
|
||||||
|
|
||||||
####### Helpers
|
####### Helpers
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ def get_whitespace(tokens, i, end):
|
|||||||
return i, text
|
return i, text
|
||||||
|
|
||||||
def get_whitespace_and_comments(tokens, i, end, line=None):
|
def get_whitespace_and_comments(tokens, i, end, line=None):
|
||||||
# type: (List[Token], int, int, int) -> Tuple[int, str]
|
# type: (List[Token], int, int, Optional[int]) -> Tuple[int, str]
|
||||||
|
|
||||||
def is_fluff_token(token):
|
def is_fluff_token(token):
|
||||||
# type: (Token) -> bool
|
# type: (Token) -> bool
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class TemplateParserException(Exception):
|
|||||||
|
|
||||||
class TokenizationException(Exception):
|
class TokenizationException(Exception):
|
||||||
def __init__(self, message, line_content=None):
|
def __init__(self, message, line_content=None):
|
||||||
# type: (str, str) -> None
|
# type: (str, Optional[str]) -> None
|
||||||
self.message = message
|
self.message = message
|
||||||
self.line_content = line_content
|
self.line_content = line_content
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def server_is_up(server, log_file):
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def test_server_running(force: bool=False, external_host: str='testserver',
|
def test_server_running(force: bool=False, external_host: str='testserver',
|
||||||
log_file: str=None, dots: bool=False, use_db: bool=True
|
log_file: Optional[str]=None, dots: bool=False, use_db: bool=True
|
||||||
) -> Iterator[None]:
|
) -> Iterator[None]:
|
||||||
log = sys.stdout
|
log = sys.stdout
|
||||||
if log_file:
|
if log_file:
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ NotSpecified = _NotSpecified()
|
|||||||
|
|
||||||
def REQ(whence: Optional[str] = None,
|
def REQ(whence: Optional[str] = None,
|
||||||
*,
|
*,
|
||||||
type: Type[ResultT] = None,
|
type: Type[ResultT] = Type[None],
|
||||||
converter: Optional[Callable[[str], ResultT]] = None,
|
converter: Optional[Callable[[str], ResultT]] = None,
|
||||||
default: Union[_NotSpecified, ResultT] = NotSpecified,
|
default: Union[_NotSpecified, ResultT] = NotSpecified,
|
||||||
validator: Optional[Validator] = None,
|
validator: Optional[Validator] = None,
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ def _check_hash(target_hash_file: str, status_dir: str) -> bool:
|
|||||||
|
|
||||||
def is_template_database_current(
|
def is_template_database_current(
|
||||||
database_name: str='zulip_test_template',
|
database_name: str='zulip_test_template',
|
||||||
migration_status: str=None,
|
migration_status: Optional[str]=None,
|
||||||
settings: str='zproject.test_settings',
|
settings: str='zproject.test_settings',
|
||||||
status_dir: str=None,
|
status_dir: Optional[str]=None,
|
||||||
check_files: Optional[List[str]]=None) -> bool:
|
check_files: Optional[List[str]]=None) -> bool:
|
||||||
# Using str type for check_files because re.split doesn't accept unicode
|
# Using str type for check_files because re.split doesn't accept unicode
|
||||||
if check_files is None:
|
if check_files is None:
|
||||||
|
|||||||
@@ -113,9 +113,9 @@ def generate_random_token(length: int) -> str:
|
|||||||
return str(base64.b16encode(os.urandom(length // 2)).decode('utf-8').lower())
|
return str(base64.b16encode(os.urandom(length // 2)).decode('utf-8').lower())
|
||||||
|
|
||||||
def query_chunker(queries: List[Any],
|
def query_chunker(queries: List[Any],
|
||||||
id_collector: Set[int]=None,
|
id_collector: Optional[Set[int]]=None,
|
||||||
chunk_size: int=1000,
|
chunk_size: int=1000,
|
||||||
db_chunk_size: int=None) -> Iterable[Any]:
|
db_chunk_size: Optional[int]=None) -> Iterable[Any]:
|
||||||
'''
|
'''
|
||||||
This merges one or more Django ascending-id queries into
|
This merges one or more Django ascending-id queries into
|
||||||
a generator that returns chunks of chunk_size row objects
|
a generator that returns chunks of chunk_size row objects
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ def check_list(sub_validator: Optional[Validator], length: Optional[int]=None) -
|
|||||||
return f
|
return f
|
||||||
|
|
||||||
def check_dict(required_keys: Iterable[Tuple[str, Validator]]=[],
|
def check_dict(required_keys: Iterable[Tuple[str, Validator]]=[],
|
||||||
value_validator: Validator=None,
|
value_validator: Optional[Validator]=None,
|
||||||
_allow_only_listed_keys: bool=False) -> Validator:
|
_allow_only_listed_keys: bool=False) -> Validator:
|
||||||
def f(var_name: str, val: object) -> Optional[str]:
|
def f(var_name: str, val: object) -> Optional[str]:
|
||||||
if not isinstance(val, dict):
|
if not isinstance(val, dict):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from typing import Any, Iterable, Text, Tuple
|
from typing import Any, Iterable, Text, Tuple, Optional
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
@@ -12,7 +12,7 @@ from zerver.models import Realm, UserProfile, \
|
|||||||
|
|
||||||
settings.TORNADO_SERVER = None
|
settings.TORNADO_SERVER = None
|
||||||
|
|
||||||
def create_users(realm: Realm, name_list: Iterable[Tuple[Text, Text]], bot_type: int=None) -> None:
|
def create_users(realm: Realm, name_list: Iterable[Tuple[Text, Text]], bot_type: Optional[int]=None) -> None:
|
||||||
user_set = set()
|
user_set = set()
|
||||||
for full_name, email in name_list:
|
for full_name, email in name_list:
|
||||||
short_name = email_to_username(email)
|
short_name = email_to_username(email)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import sys
|
|||||||
from io import StringIO
|
from io import StringIO
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from typing import Any, Callable, Dict, Mapping, Union, Text
|
from typing import Any, Callable, Dict, Mapping, Union, Text, Optional
|
||||||
|
|
||||||
class TestEmailMirrorLibrary(ZulipTestCase):
|
class TestEmailMirrorLibrary(ZulipTestCase):
|
||||||
def test_get_missed_message_token(self) -> None:
|
def test_get_missed_message_token(self) -> None:
|
||||||
@@ -406,7 +406,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
|
|||||||
|
|
||||||
def check_queue_json_publish(queue_name: str,
|
def check_queue_json_publish(queue_name: str,
|
||||||
event: Union[Mapping[str, Any], str],
|
event: Union[Mapping[str, Any], str],
|
||||||
processor: Callable[[Any], None]=None) -> None:
|
processor: Optional[Callable[[Any], None]]=None) -> None:
|
||||||
self.assertEqual(queue_name, "email_mirror")
|
self.assertEqual(queue_name, "email_mirror")
|
||||||
self.assertEqual(event, {"rcpt_to": to_address, "message": mail})
|
self.assertEqual(event, {"rcpt_to": to_address, "message": mail})
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import shutil
|
|||||||
import ujson
|
import ujson
|
||||||
|
|
||||||
from mock import patch, MagicMock
|
from mock import patch, MagicMock
|
||||||
from typing import Any, Dict, List, Set
|
from typing import Any, Dict, List, Set, Optional
|
||||||
|
|
||||||
from zerver.lib.actions import (
|
from zerver.lib.actions import (
|
||||||
do_claim_attachments,
|
do_claim_attachments,
|
||||||
@@ -181,7 +181,7 @@ class ExportTest(ZulipTestCase):
|
|||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
return output_dir
|
return output_dir
|
||||||
|
|
||||||
def _export_realm(self, realm: Realm, exportable_user_ids: Set[int]=None) -> Dict[str, Any]:
|
def _export_realm(self, realm: Realm, exportable_user_ids: Optional[Set[int]]=None) -> Dict[str, Any]:
|
||||||
output_dir = self._make_output_dir()
|
output_dir = self._make_output_dir()
|
||||||
with patch('logging.info'), patch('zerver.lib.export.create_soft_link'):
|
with patch('logging.info'), patch('zerver.lib.export.create_soft_link'):
|
||||||
do_export_realm(
|
do_export_realm(
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from django.http import HttpResponse
|
|||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
from email.utils import formataddr
|
from email.utils import formataddr
|
||||||
from mock import patch, MagicMock
|
from mock import patch, MagicMock
|
||||||
from typing import Any, Dict, List, Text
|
from typing import Any, Dict, List, Text, Optional
|
||||||
|
|
||||||
from zerver.lib.notifications import fix_emojis, \
|
from zerver.lib.notifications import fix_emojis, \
|
||||||
handle_missedmessage_emails, relative_to_full_url
|
handle_missedmessage_emails, relative_to_full_url
|
||||||
@@ -39,7 +39,7 @@ class TestMissedMessages(ZulipTestCase):
|
|||||||
def _test_cases(self, tokens: List[str], msg_id: int, body: str, subject: str,
|
def _test_cases(self, tokens: List[str], msg_id: int, body: str, subject: str,
|
||||||
send_as_user: bool, verify_html_body: bool=False,
|
send_as_user: bool, verify_html_body: bool=False,
|
||||||
show_message_content: bool=True,
|
show_message_content: bool=True,
|
||||||
verify_body_does_not_include: List[str]=None) -> None:
|
verify_body_does_not_include: Optional[List[str]]=None) -> None:
|
||||||
othello = self.example_user('othello')
|
othello = self.example_user('othello')
|
||||||
hamlet = self.example_user('hamlet')
|
hamlet = self.example_user('hamlet')
|
||||||
handle_missedmessage_emails(hamlet.id, [{'message_id': msg_id}])
|
handle_missedmessage_emails(hamlet.id, [{'message_id': msg_id}])
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ def get_in(payload: Dict[str, Any], keys: List[str], default: Text='') -> Any:
|
|||||||
return default
|
return default
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
def get_issue_string(payload: Dict[str, Any], issue_id: Text=None) -> Text:
|
def get_issue_string(payload: Dict[str, Any], issue_id: Optional[Text]=None) -> Text:
|
||||||
# Guess the URL as it is not specified in the payload
|
# Guess the URL as it is not specified in the payload
|
||||||
# We assume that there is a /browse/BUG-### page
|
# We assume that there is a /browse/BUG-### page
|
||||||
# from the REST url of the issue itself
|
# from the REST url of the issue itself
|
||||||
|
|||||||
Reference in New Issue
Block a user