mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 03:53:50 +00:00 
			
		
		
		
	mypy: Add explicit Optional for default=None parameters in various files.
This commit is contained in:
		
				
					committed by
					
						 Tim Abbott
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							9a90c225a6
						
					
				
				
					commit
					090b47ed19
				
			| @@ -26,7 +26,7 @@ django.setup() | ||||
| from zerver.models import UserActivity | ||||
|  | ||||
| if False: | ||||
|     from typing import Any, Dict, Set | ||||
|     from typing import Any, Dict, Set, Optional | ||||
|  | ||||
| states = { | ||||
|     "OK": 0, | ||||
| @@ -36,7 +36,7 @@ states = { | ||||
| }  # type: Dict[str, int] | ||||
|  | ||||
| def report(state, short_msg, too_old=None): | ||||
|     # type: (str, str, Set[Any]) -> None | ||||
|     # type: (str, str, Optional[Set[Any]]) -> None | ||||
|     too_old_data = "" | ||||
|     if too_old: | ||||
|         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 | ||||
|  | ||||
| @@ -50,7 +50,7 @@ def get_whitespace(tokens, i, end): | ||||
|     return i, text | ||||
|  | ||||
| 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): | ||||
|         # type: (Token) -> bool | ||||
|   | ||||
| @@ -11,7 +11,7 @@ class TemplateParserException(Exception): | ||||
|  | ||||
| class TokenizationException(Exception): | ||||
|     def __init__(self, message, line_content=None): | ||||
|         # type: (str, str) -> None | ||||
|         # type: (str, Optional[str]) -> None | ||||
|         self.message = message | ||||
|         self.line_content = line_content | ||||
|  | ||||
|   | ||||
| @@ -49,7 +49,7 @@ def server_is_up(server, log_file): | ||||
|  | ||||
| @contextmanager | ||||
| 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]: | ||||
|     log = sys.stdout | ||||
|     if log_file: | ||||
|   | ||||
| @@ -21,7 +21,7 @@ NotSpecified = _NotSpecified() | ||||
|  | ||||
| def REQ(whence: Optional[str] = None, | ||||
|         *, | ||||
|         type: Type[ResultT] = None, | ||||
|         type: Type[ResultT] = Type[None], | ||||
|         converter: Optional[Callable[[str], ResultT]] = None, | ||||
|         default: Union[_NotSpecified, ResultT] = NotSpecified, | ||||
|         validator: Optional[Validator] = None, | ||||
|   | ||||
| @@ -95,9 +95,9 @@ def _check_hash(target_hash_file: str, status_dir: str) -> bool: | ||||
|  | ||||
| def is_template_database_current( | ||||
|         database_name: str='zulip_test_template', | ||||
|         migration_status: str=None, | ||||
|         migration_status: Optional[str]=None, | ||||
|         settings: str='zproject.test_settings', | ||||
|         status_dir: str=None, | ||||
|         status_dir: Optional[str]=None, | ||||
|         check_files: Optional[List[str]]=None) -> bool: | ||||
|     # Using str type for check_files because re.split doesn't accept unicode | ||||
|     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()) | ||||
|  | ||||
| def query_chunker(queries: List[Any], | ||||
|                   id_collector: Set[int]=None, | ||||
|                   id_collector: Optional[Set[int]]=None, | ||||
|                   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 | ||||
|     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 | ||||
|  | ||||
| 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: | ||||
|     def f(var_name: str, val: object) -> Optional[str]: | ||||
|         if not isinstance(val, dict): | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
|  | ||||
| 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.contrib.sites.models import Site | ||||
| @@ -12,7 +12,7 @@ from zerver.models import Realm, UserProfile, \ | ||||
|  | ||||
| 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() | ||||
|     for full_name, email in name_list: | ||||
|         short_name = email_to_username(email) | ||||
|   | ||||
| @@ -45,7 +45,7 @@ import sys | ||||
| from io import StringIO | ||||
| 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): | ||||
|     def test_get_missed_message_token(self) -> None: | ||||
| @@ -406,7 +406,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase): | ||||
|  | ||||
|         def check_queue_json_publish(queue_name: 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(event, {"rcpt_to": to_address, "message": mail}) | ||||
|  | ||||
|   | ||||
| @@ -8,7 +8,7 @@ import shutil | ||||
| import ujson | ||||
|  | ||||
| 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 ( | ||||
|     do_claim_attachments, | ||||
| @@ -181,7 +181,7 @@ class ExportTest(ZulipTestCase): | ||||
|         os.makedirs(output_dir, exist_ok=True) | ||||
|         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() | ||||
|         with patch('logging.info'), patch('zerver.lib.export.create_soft_link'): | ||||
|             do_export_realm( | ||||
|   | ||||
| @@ -10,7 +10,7 @@ from django.http import HttpResponse | ||||
| from django.test import override_settings | ||||
| from email.utils import formataddr | ||||
| 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, \ | ||||
|     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, | ||||
|                     send_as_user: bool, verify_html_body: bool=False, | ||||
|                     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') | ||||
|         hamlet = self.example_user('hamlet') | ||||
|         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 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 | ||||
|     # We assume that there is a /browse/BUG-### page | ||||
|     # from the REST url of the issue itself | ||||
|   | ||||
		Reference in New Issue
	
	Block a user