From a276eefcfec5984de8d028197aeebb2aec0c9eec Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 1 Sep 2020 23:14:51 -0700 Subject: [PATCH] python: Rewrite dict() as {}. Suggested by the flake8-comprehensions plugin. Signed-off-by: Anders Kaseorg --- scripts/lib/check_rabbitmq_queue.py | 4 ++-- tools/create-test-api-docs | 2 +- zerver/data_import/hipchat.py | 2 +- zerver/data_import/hipchat_attachment.py | 2 +- zerver/data_import/hipchat_user.py | 4 ++-- zerver/data_import/import_util.py | 6 +++--- zerver/data_import/mattermost.py | 2 +- zerver/data_import/mattermost_user.py | 2 +- zerver/data_import/sequencer.py | 4 ++-- zerver/lib/alert_words.py | 2 +- zerver/lib/bot_config.py | 2 +- zerver/lib/bot_lib.py | 2 +- zerver/lib/events.py | 2 +- zerver/lib/markdown/__init__.py | 8 ++++---- zerver/lib/message.py | 2 +- zerver/lib/presence.py | 6 +++--- zerver/lib/stream_recipient.py | 4 ++-- zerver/lib/user_status.py | 4 ++-- zerver/lib/zcommand.py | 2 +- zerver/middleware.py | 2 +- .../0224_alter_field_realm_video_chat_provider.py | 2 +- zerver/migrations/0277_migrate_alert_word.py | 2 +- zerver/openapi/curl_param_value_generators.py | 2 +- zerver/openapi/markdown_extension.py | 2 +- zerver/openapi/openapi.py | 2 +- zerver/openapi/python_examples.py | 2 +- zerver/tests/test_auth_backends.py | 14 +++++++------- zerver/tests/test_docs.py | 12 ++++++------ zerver/tests/test_message_edit.py | 2 +- zerver/tests/test_message_fetch.py | 4 ++-- zerver/tests/test_message_flags.py | 2 +- zerver/tests/test_message_topics.py | 14 +++++++------- zerver/tests/test_mirror_users.py | 2 +- zerver/tests/test_openapi.py | 2 +- zerver/tests/test_outgoing_webhook_interfaces.py | 2 +- zerver/tests/test_service_bot_system.py | 2 +- zerver/tests/test_signup.py | 2 +- zerver/tests/test_slack_importer.py | 2 +- zerver/tests/test_user_status.py | 6 +++--- zerver/tests/test_users.py | 2 +- zerver/tests/test_widgets.py | 2 +- zerver/tornado/event_queue.py | 2 +- zerver/views/message_fetch.py | 4 ++-- zerver/views/streams.py | 2 +- zerver/webhooks/bitbucket3/view.py | 2 +- zilencer/management/commands/populate_db.py | 2 +- 46 files changed, 79 insertions(+), 79 deletions(-) diff --git a/scripts/lib/check_rabbitmq_queue.py b/scripts/lib/check_rabbitmq_queue.py index 0743a2d271..60a385bff3 100644 --- a/scripts/lib/check_rabbitmq_queue.py +++ b/scripts/lib/check_rabbitmq_queue.py @@ -155,7 +155,7 @@ def check_rabbitmq_queues() -> None: list_consumers_output = subprocess.check_output(['/usr/sbin/rabbitmqctl', 'list_consumers'], universal_newlines=True) - queue_counts_rabbitmqctl = dict() + queue_counts_rabbitmqctl = {} for line in list_queues_output.split("\n"): line = line.strip() m = pattern.match(line) @@ -176,7 +176,7 @@ def check_rabbitmq_queues() -> None: queue_stats_dir = subprocess.check_output([os.path.join(ZULIP_PATH, 'scripts/get-django-setting'), 'QUEUE_STATS_DIR'], universal_newlines=True).strip() - queue_stats: Dict[str, Dict[str, Any]] = dict() + queue_stats: Dict[str, Dict[str, Any]] = {} queues_to_check = set(normal_queues).intersection(set(queues_with_consumers)) for queue in queues_to_check: fn = queue + ".stats" diff --git a/tools/create-test-api-docs b/tools/create-test-api-docs index 5ee02cefd6..7031f958ad 100755 --- a/tools/create-test-api-docs +++ b/tools/create-test-api-docs @@ -124,7 +124,7 @@ def create_user_docs() -> None: ('json', 'legacy'), ] - groups: Dict[str, Set[str]] = dict() + groups: Dict[str, Set[str]] = {} for prefix, name in tups: groups[name] = {p for p in patterns if p.startswith(prefix)} patterns -= groups[name] diff --git a/zerver/data_import/hipchat.py b/zerver/data_import/hipchat.py index 9910270399..4f23007705 100755 --- a/zerver/data_import/hipchat.py +++ b/zerver/data_import/hipchat.py @@ -661,7 +661,7 @@ def process_raw_message_batch(realm_id: int, content = content.replace('@here', '@**all**') return content - mention_map: Dict[int, Set[int]] = dict() + mention_map: Dict[int, Set[int]] = {} zerver_message = [] diff --git a/zerver/data_import/hipchat_attachment.py b/zerver/data_import/hipchat_attachment.py index 596d3e588f..5193f4afe0 100644 --- a/zerver/data_import/hipchat_attachment.py +++ b/zerver/data_import/hipchat_attachment.py @@ -8,7 +8,7 @@ from zerver.data_import.import_util import build_attachment, create_converted_da class AttachmentHandler: def __init__(self) -> None: - self.info_dict: Dict[str, Dict[str, Any]] = dict() + self.info_dict: Dict[str, Dict[str, Any]] = {} def handle_message_data(self, realm_id: int, diff --git a/zerver/data_import/hipchat_user.py b/zerver/data_import/hipchat_user.py index ef03ece81b..b751239f40 100644 --- a/zerver/data_import/hipchat_user.py +++ b/zerver/data_import/hipchat_user.py @@ -20,8 +20,8 @@ class UserHandler: ''' def __init__(self) -> None: - self.id_to_user_map: Dict[int, Dict[str, Any]] = dict() - self.name_to_mirror_user_map: Dict[str, Dict[str, Any]] = dict() + self.id_to_user_map: Dict[int, Dict[str, Any]] = {} + self.name_to_mirror_user_map: Dict[str, Dict[str, Any]] = {} self.mirror_user_id = 1 def add_user(self, user: Dict[str, Any]) -> None: diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py index f4e0b4e535..5281416ca9 100644 --- a/zerver/data_import/import_util.py +++ b/zerver/data_import/import_util.py @@ -41,8 +41,8 @@ ZerverFieldsT = Dict[str, Any] class SubscriberHandler: def __init__(self) -> None: - self.stream_info: Dict[int, Set[int]] = dict() - self.huddle_info: Dict[int, Set[int]] = dict() + self.stream_info: Dict[int, Set[int]] = {} + self.huddle_info: Dict[int, Set[int]] = {} def set_info(self, users: Set[int], @@ -129,7 +129,7 @@ def make_subscriber_map(zerver_subscription: List[ZerverFieldsT]) -> Dict[int, S This can be convenient for building up UserMessage rows. ''' - subscriber_map: Dict[int, Set[int]] = dict() + subscriber_map: Dict[int, Set[int]] = {} for sub in zerver_subscription: user_id = sub['user_profile'] recipient_id = sub['recipient'] diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py index 14ab4f88da..8be5e7e1b6 100644 --- a/zerver/data_import/mattermost.py +++ b/zerver/data_import/mattermost.py @@ -319,7 +319,7 @@ def process_raw_message_batch(realm_id: int, content = content.replace('@here', '@**all**') return content - mention_map: Dict[int, Set[int]] = dict() + mention_map: Dict[int, Set[int]] = {} zerver_message = [] import html2text diff --git a/zerver/data_import/mattermost_user.py b/zerver/data_import/mattermost_user.py index e6d629314e..3c3f9e40cc 100644 --- a/zerver/data_import/mattermost_user.py +++ b/zerver/data_import/mattermost_user.py @@ -12,7 +12,7 @@ class UserHandler: ''' def __init__(self) -> None: - self.id_to_user_map: Dict[int, Dict[str, Any]] = dict() + self.id_to_user_map: Dict[int, Dict[str, Any]] = {} def add_user(self, user: Dict[str, Any]) -> None: user_id = user['id'] diff --git a/zerver/data_import/sequencer.py b/zerver/data_import/sequencer.py index c526c82250..46d8192aa3 100644 --- a/zerver/data_import/sequencer.py +++ b/zerver/data_import/sequencer.py @@ -28,7 +28,7 @@ def sequencer() -> Callable[[str], int]: NEXT_ID = sequencer() message_id = NEXT_ID('message') ''' - seq_dict: Dict[str, Callable[[], int]] = dict() + seq_dict: Dict[str, Callable[[], int]] = {} def next_one(name: str) -> int: if name not in seq_dict: @@ -59,7 +59,7 @@ def is_int(key: Any) -> bool: class IdMapper: def __init__(self) -> None: - self.map: Dict[Any, int] = dict() + self.map: Dict[Any, int] = {} self.cnt = 0 def has(self, their_id: Any) -> bool: diff --git a/zerver/lib/alert_words.py b/zerver/lib/alert_words.py index e9658d9b97..42975c57ef 100644 --- a/zerver/lib/alert_words.py +++ b/zerver/lib/alert_words.py @@ -15,7 +15,7 @@ from zerver.models import AlertWord, Realm, UserProfile, flush_realm_alert_words def alert_words_in_realm(realm: Realm) -> Dict[int, List[str]]: user_ids_and_words = AlertWord.objects.filter( realm=realm, user_profile__is_active=True).values("user_profile_id", "word") - user_ids_with_words: Dict[int, List[str]] = dict() + user_ids_with_words: Dict[int, List[str]] = {} for id_and_word in user_ids_and_words: user_ids_with_words.setdefault(id_and_word["user_profile_id"], []) user_ids_with_words[id_and_word["user_profile_id"]].append(id_and_word["word"]) diff --git a/zerver/lib/bot_config.py b/zerver/lib/bot_config.py index 40e74559cc..e4bf3c873e 100644 --- a/zerver/lib/bot_config.py +++ b/zerver/lib/bot_config.py @@ -68,4 +68,4 @@ def load_bot_config_template(bot: str) -> Dict[str, str]: config.read_file(conf) return dict(config.items(bot)) else: - return dict() + return {} diff --git a/zerver/lib/bot_lib.py b/zerver/lib/bot_lib.py index 413b449666..9ba4e92e87 100644 --- a/zerver/lib/bot_lib.py +++ b/zerver/lib/bot_lib.py @@ -125,7 +125,7 @@ class EmbeddedBotHandler: return get_bot_config(self.user_profile) except ConfigError: if optional: - return dict() + return {} raise def quit(self, message: str= "") -> None: diff --git a/zerver/lib/events.py b/zerver/lib/events.py index 69f13c671e..a1f387c0f7 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -810,7 +810,7 @@ def apply_event(state: Dict[str, Any], status_text = event.get('status_text') if user_id_str not in user_status: - user_status[user_id_str] = dict() + user_status[user_id_str] = {} if away is not None: if away: diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index a2493608df..8b661d4f29 100644 --- a/zerver/lib/markdown/__init__.py +++ b/zerver/lib/markdown/__init__.py @@ -754,7 +754,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor): # and gifs do not work. # TODO: What if image is huge? Should we get headers first? if image_info is None: - image_info = dict() + image_info = {} image_info['is_image'] = True parsed_url_list = list(parsed_url) parsed_url_list[4] = "dl=1" # Replaces query @@ -2217,7 +2217,7 @@ class MentionData: def get_user_group_name_info(realm_id: int, user_group_names: Set[str]) -> Dict[str, UserGroup]: if not user_group_names: - return dict() + return {} rows = UserGroup.objects.filter(realm_id=realm_id, name__in=user_group_names) @@ -2226,7 +2226,7 @@ def get_user_group_name_info(realm_id: int, user_group_names: Set[str]) -> Dict[ def get_stream_name_info(realm: Realm, stream_names: Set[str]) -> Dict[str, FullNameInfo]: if not stream_names: - return dict() + return {} q_list = { Q(name=name) @@ -2323,7 +2323,7 @@ def do_convert(content: str, if content_has_emoji_syntax(content): active_realm_emoji = message_realm.get_active_emoji() else: - active_realm_emoji = dict() + active_realm_emoji = {} _md_engine.zulip_db_data = { 'realm_alert_words_automaton': realm_alert_words_automaton, diff --git a/zerver/lib/message.py b/zerver/lib/message.py index ab1f167f25..f09437d93f 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -730,7 +730,7 @@ def huddle_users(recipient_id: int) -> str: def aggregate_message_dict(input_dict: Dict[int, Dict[str, Any]], lookup_fields: List[str], collect_senders: bool) -> List[Dict[str, Any]]: - lookup_dict: Dict[Tuple[Any, ...], Dict[str, Any]] = dict() + lookup_dict: Dict[Tuple[Any, ...], Dict[str, Any]] = {} ''' A concrete example might help explain the inputs here: diff --git a/zerver/lib/presence.py b/zerver/lib/presence.py index 425153f628..a2d97a8a90 100644 --- a/zerver/lib/presence.py +++ b/zerver/lib/presence.py @@ -33,7 +33,7 @@ def get_status_dicts_for_rows(all_rows: List[Dict[str, Any]], get_user_key = lambda row: row['user_profile__email'] get_user_info = get_legacy_user_info - user_statuses: Dict[str, Dict[str, Any]] = dict() + user_statuses: Dict[str, Dict[str, Any]] = {} for user_key, presence_rows in itertools.groupby(all_rows, get_user_key): info = get_user_info( @@ -64,7 +64,7 @@ def get_modern_user_info(presence_rows: List[Dict[str, Any]], # Be stingy about bandwidth, and don't even include # keys for entities that have None values. JS # code should just do a falsy check here. - result = dict() + result = {} if active_timestamp is not None: result['active_timestamp'] = active_timestamp @@ -100,7 +100,7 @@ def get_legacy_user_info(presence_rows: List[Dict[str, Any]], most_recent_info = info_rows[-1] - result = dict() + result = {} # The word "aggegrated" here is possibly misleading. # It's really just the most recent client's info. diff --git a/zerver/lib/stream_recipient.py b/zerver/lib/stream_recipient.py index 4f9f5f7ffe..596c0317a9 100644 --- a/zerver/lib/stream_recipient.py +++ b/zerver/lib/stream_recipient.py @@ -21,8 +21,8 @@ class StreamRecipientMap: ''' def __init__(self) -> None: - self.recip_to_stream: Dict[int, int] = dict() - self.stream_to_recip: Dict[int, int] = dict() + self.recip_to_stream: Dict[int, int] = {} + self.stream_to_recip: Dict[int, int] = {} def populate_with(self, *, stream_id: int, recipient_id: int) -> None: # We use * to enforce using named arguments when calling this function, diff --git a/zerver/lib/user_status.py b/zerver/lib/user_status.py index f57ca6667d..a21a6c0b08 100644 --- a/zerver/lib/user_status.py +++ b/zerver/lib/user_status.py @@ -19,13 +19,13 @@ def get_user_info_dict(realm_id: int) -> Dict[str, Dict[str, Any]]: 'status_text', ) - user_dict: Dict[str, Dict[str, Any]] = dict() + user_dict: Dict[str, Dict[str, Any]] = {} for row in rows: away = row['status'] == UserStatus.AWAY status_text = row['status_text'] user_id = row['user_profile_id'] - dct = dict() + dct = {} if away: dct['away'] = away if status_text: diff --git a/zerver/lib/zcommand.py b/zerver/lib/zcommand.py index 14ed4b9179..4003a5bb84 100644 --- a/zerver/lib/zcommand.py +++ b/zerver/lib/zcommand.py @@ -25,7 +25,7 @@ def process_zcommands(content: str, user_profile: UserProfile) -> Dict[str, Any] command = content[1:] if command == 'ping': - return dict() + return {} elif command == 'night': if user_profile.color_scheme == UserProfile.COLOR_SCHEME_NIGHT: return dict(msg='You are still in night mode.') diff --git a/zerver/middleware.py b/zerver/middleware.py index 74306940f8..1c360089d6 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -239,7 +239,7 @@ class LogRequests(MiddlewareMixin): # Avoid re-initializing request._log_data if it's already there. return - request._log_data = dict() + request._log_data = {} record_request_start_data(request._log_data) def process_view(self, request: HttpRequest, view_func: ViewFuncT, diff --git a/zerver/migrations/0224_alter_field_realm_video_chat_provider.py b/zerver/migrations/0224_alter_field_realm_video_chat_provider.py index 2b2d460aec..ee36efd51a 100644 --- a/zerver/migrations/0224_alter_field_realm_video_chat_provider.py +++ b/zerver/migrations/0224_alter_field_realm_video_chat_provider.py @@ -30,7 +30,7 @@ def get_video_chat_provider_detail(providers_dict: Dict[str, Dict[str, Any]], return provider if (p_id and provider['id'] == p_id): return provider - return dict() + return {} def update_existing_video_chat_provider_values(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None: Realm = apps.get_model('zerver', 'Realm') diff --git a/zerver/migrations/0277_migrate_alert_word.py b/zerver/migrations/0277_migrate_alert_word.py index a5bba106e7..0021aad471 100644 --- a/zerver/migrations/0277_migrate_alert_word.py +++ b/zerver/migrations/0277_migrate_alert_word.py @@ -28,7 +28,7 @@ def move_back_to_user_profile(apps: StateApps, schema_editor: DatabaseSchemaEdit UserProfile = apps.get_model('zerver', 'UserProfile') user_ids_and_words = AlertWord.objects.all().values("user_profile_id", "word") - user_ids_with_words: Dict[int, List[str]] = dict() + user_ids_with_words: Dict[int, List[str]] = {} for id_and_word in user_ids_and_words: user_ids_with_words.setdefault(id_and_word["user_profile_id"], []) diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.py index 0cb33526cd..7ecf64802e 100644 --- a/zerver/openapi/curl_param_value_generators.py +++ b/zerver/openapi/curl_param_value_generators.py @@ -8,7 +8,7 @@ from zerver.lib.events import do_events_register from zerver.lib.test_classes import ZulipTestCase from zerver.models import Client, Message, UserGroup, UserPresence, get_realm -GENERATOR_FUNCTIONS: Dict[str, Callable[[], Dict[str, object]]] = dict() +GENERATOR_FUNCTIONS: Dict[str, Callable[[], Dict[str, object]]] = {} REGISTERED_GENERATOR_FUNCTIONS: Set[str] = set() CALLED_GENERATOR_FUNCTIONS: Set[str] = set() diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py index c5ea162947..f26b1fefd4 100644 --- a/zerver/openapi/markdown_extension.py +++ b/zerver/openapi/markdown_extension.py @@ -306,7 +306,7 @@ def render_curl_example(function: str, api_url: str, parts = function.split(":") endpoint = parts[0] method = parts[1] - kwargs: Dict[str, Any] = dict() + kwargs: Dict[str, Any] = {} if len(parts) > 2: kwargs["auth_email"] = parts[2] if len(parts) > 3: diff --git a/zerver/openapi/openapi.py b/zerver/openapi/openapi.py index 045ec3500a..09b1389de8 100644 --- a/zerver/openapi/openapi.py +++ b/zerver/openapi/openapi.py @@ -266,7 +266,7 @@ def validate_schema(schema: Dict[str, Any]) -> None: if 'additionalProperties' not in schema: raise SchemaError('additionalProperties needs to be defined for objects to make' + 'sure they have no additional properties left to be documented.') - for property_schema in schema.get('properties', dict()).values(): + for property_schema in schema.get('properties', {}).values(): validate_schema(property_schema) if schema['additionalProperties']: validate_schema(schema['additionalProperties']) diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.py index 4a7ed76e2a..0363015e6b 100644 --- a/zerver/openapi/python_examples.py +++ b/zerver/openapi/python_examples.py @@ -12,7 +12,7 @@ from zerver.openapi.openapi import validate_against_openapi_schema ZULIP_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -TEST_FUNCTIONS: Dict[str, Callable[..., object]] = dict() +TEST_FUNCTIONS: Dict[str, Callable[..., object]] = {} REGISTERED_TEST_FUNCTIONS: Set[str] = set() CALLED_TEST_FUNCTIONS: Set[str] = set() diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 93f96f6c79..509dfc04db 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -255,23 +255,23 @@ class AuthBackendTest(ZulipTestCase): password=password, username=username, realm=get_realm('zulip'), - return_data=dict()), + return_data={}), bad_kwargs=dict(request=mock.MagicMock(), password=password, username=username, realm=get_realm('zephyr'), - return_data=dict())) + return_data={})) self.verify_backend(EmailAuthBackend(), good_kwargs=dict(request=mock.MagicMock(), password=password, username=username, realm=get_realm('zulip'), - return_data=dict()), + return_data={}), bad_kwargs=dict(request=mock.MagicMock(), password=password, username=username, realm=get_realm('zephyr'), - return_data=dict())) + return_data={})) def test_email_auth_backend_empty_password(self) -> None: user_profile = self.example_user('hamlet') @@ -600,7 +600,7 @@ class RateLimitAuthenticationTests(ZulipTestCase): username=username, realm=get_realm("zulip"), password=password, - return_data=dict()) + return_data={}) self.do_test_auth_rate_limiting(attempt_authentication, user_profile.delivery_email, @@ -619,7 +619,7 @@ class RateLimitAuthenticationTests(ZulipTestCase): username=username, realm=get_realm("zulip"), password=password, - return_data=dict()) + return_data={}) self.do_test_auth_rate_limiting(attempt_authentication, user_profile.delivery_email, @@ -643,7 +643,7 @@ class RateLimitAuthenticationTests(ZulipTestCase): username=username, realm=get_realm("zulip"), password=password, - return_data=dict()) + return_data={}) self.do_test_auth_rate_limiting(attempt_authentication, user_profile.delivery_email, diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index 4bb7a93529..c41ca86894 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -274,7 +274,7 @@ class IntegrationTest(ZulipTestCase): self.assertTrue(os.path.isfile(settings.DEPLOY_ROOT + path), integration.name) def test_api_url_view_subdomains_base(self) -> None: - context: Dict[str, Any] = dict() + context: Dict[str, Any] = {} add_api_uri_context(context, HostRequestMock()) self.assertEqual(context["api_url_scheme_relative"], "testserver/api") self.assertEqual(context["api_url"], "http://testserver/api") @@ -282,14 +282,14 @@ class IntegrationTest(ZulipTestCase): @override_settings(ROOT_DOMAIN_LANDING_PAGE=True) def test_api_url_view_subdomains_homepage_base(self) -> None: - context: Dict[str, Any] = dict() + context: Dict[str, Any] = {} add_api_uri_context(context, HostRequestMock()) self.assertEqual(context["api_url_scheme_relative"], "yourZulipDomain.testserver/api") self.assertEqual(context["api_url"], "http://yourZulipDomain.testserver/api") self.assertFalse(context["html_settings_links"]) def test_api_url_view_subdomains_full(self) -> None: - context: Dict[str, Any] = dict() + context: Dict[str, Any] = {} request = HostRequestMock(host="mysubdomain.testserver") add_api_uri_context(context, request) self.assertEqual(context["api_url_scheme_relative"], "mysubdomain.testserver/api") @@ -297,7 +297,7 @@ class IntegrationTest(ZulipTestCase): self.assertTrue(context["html_settings_links"]) def test_html_settings_links(self) -> None: - context: Dict[str, Any] = dict() + context: Dict[str, Any] = {} with self.settings(ROOT_DOMAIN_LANDING_PAGE=True): add_api_uri_context(context, HostRequestMock()) self.assertEqual( @@ -307,7 +307,7 @@ class IntegrationTest(ZulipTestCase): context['subscriptions_html'], 'streams page') - context = dict() + context = {} with self.settings(ROOT_DOMAIN_LANDING_PAGE=True): add_api_uri_context(context, HostRequestMock(host="mysubdomain.testserver")) self.assertEqual( @@ -317,7 +317,7 @@ class IntegrationTest(ZulipTestCase): context['subscriptions_html'], 'streams page') - context = dict() + context = {} add_api_uri_context(context, HostRequestMock()) self.assertEqual( context['settings_html'], diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py index 35b6eed21c..6a740aade3 100644 --- a/zerver/tests/test_message_edit.py +++ b/zerver/tests/test_message_edit.py @@ -47,7 +47,7 @@ class EditMessageTest(ZulipTestCase): (fetch_message_dict,) = messages_for_ids( message_ids = [msg.id], user_message_flags={msg_id: []}, - search_fields=dict(), + search_fields={}, apply_markdown=False, client_gravatar=False, allow_edit_history=True, diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py index 07414fc91f..2eb7924ab3 100644 --- a/zerver/tests/test_message_fetch.py +++ b/zerver/tests/test_message_fetch.py @@ -1151,7 +1151,7 @@ class GetOldMessagesTest(ZulipTestCase): Test old `/json/messages` returns reactions. """ self.login('hamlet') - messages = self.get_and_check_messages(dict()) + messages = self.get_and_check_messages({}) message_id = messages['messages'][0]['id'] self.login('othello') @@ -1182,7 +1182,7 @@ class GetOldMessagesTest(ZulipTestCase): messages. """ self.login('hamlet') - self.get_and_check_messages(dict()) + self.get_and_check_messages({}) othello_email = self.example_user('othello').email diff --git a/zerver/tests/test_message_flags.py b/zerver/tests/test_message_flags.py index 085a41a1a6..b39b72c3dc 100644 --- a/zerver/tests/test_message_flags.py +++ b/zerver/tests/test_message_flags.py @@ -507,7 +507,7 @@ class GetUnreadMsgsTest(ZulipTestCase): self.subscribe(cordelia, stream_name) all_message_ids: Set[int] = set() - message_ids = dict() + message_ids = {} tups = [ ('social', 'lunch'), diff --git a/zerver/tests/test_message_topics.py b/zerver/tests/test_message_topics.py index a8516d6b24..4f342e58bc 100644 --- a/zerver/tests/test_message_topics.py +++ b/zerver/tests/test_message_topics.py @@ -21,7 +21,7 @@ class TopicHistoryTest(ZulipTestCase): self.login_user(user_profile) self.subscribe(user_profile, stream_name) endpoint = f'/json/users/me/{stream.id}/topics' - result = self.client_get(endpoint, dict(), subdomain="zephyr") + result = self.client_get(endpoint, {}, subdomain="zephyr") self.assert_json_success(result) history = result.json()['topics'] self.assertEqual(history, []) @@ -75,7 +75,7 @@ class TopicHistoryTest(ZulipTestCase): topic0_msg_id = create_test_message('topic0') endpoint = f'/json/users/me/{stream.id}/topics' - result = self.client_get(endpoint, dict()) + result = self.client_get(endpoint, {}) self.assert_json_success(result) history = result.json()['topics'] @@ -99,7 +99,7 @@ class TopicHistoryTest(ZulipTestCase): # that she doesn't have UserMessage rows. We should see the # same results for a public stream. self.login('cordelia') - result = self.client_get(endpoint, dict()) + result = self.client_get(endpoint, {}) self.assert_json_success(result) history = result.json()['topics'] @@ -124,7 +124,7 @@ class TopicHistoryTest(ZulipTestCase): do_change_stream_invite_only(stream, True) self.subscribe(self.example_user("cordelia"), stream.name) - result = self.client_get(endpoint, dict()) + result = self.client_get(endpoint, {}) self.assert_json_success(result) history = result.json()['topics'] history = history[:3] @@ -140,7 +140,7 @@ class TopicHistoryTest(ZulipTestCase): # non-sensible stream id endpoint = '/json/users/me/9999999999/topics' - result = self.client_get(endpoint, dict()) + result = self.client_get(endpoint, {}) self.assert_json_error(result, 'Invalid stream id') # out of realm @@ -149,7 +149,7 @@ class TopicHistoryTest(ZulipTestCase): realm=get_realm('zephyr'), ) endpoint = f'/json/users/me/{bad_stream.id}/topics' - result = self.client_get(endpoint, dict()) + result = self.client_get(endpoint, {}) self.assert_json_error(result, 'Invalid stream id') # private stream to which I am not subscribed @@ -158,7 +158,7 @@ class TopicHistoryTest(ZulipTestCase): invite_only=True, ) endpoint = f'/json/users/me/{private_stream.id}/topics' - result = self.client_get(endpoint, dict()) + result = self.client_get(endpoint, {}) self.assert_json_error(result, 'Invalid stream id') class TopicDeleteTest(ZulipTestCase): diff --git a/zerver/tests/test_mirror_users.py b/zerver/tests/test_mirror_users.py index 915dad5b62..c1fd069bcf 100644 --- a/zerver/tests/test_mirror_users.py +++ b/zerver/tests/test_mirror_users.py @@ -19,7 +19,7 @@ class MirroredMessageUsersTest(ZulipTestCase): recipients: List[str] = [] Request = namedtuple('Request', ['POST']) - request = Request(POST=dict()) # no sender + request = Request(POST={}) # no sender with self.assertRaises(InvalidMirrorInput): create_mirrored_message_users(request, user, recipients) diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py index 632c94c069..0d0a76b591 100644 --- a/zerver/tests/test_openapi.py +++ b/zerver/tests/test_openapi.py @@ -433,7 +433,7 @@ do not match the types declared in the implementation of {function.__name__}.\n" Otherwise, we print out the exact differences for convenient debugging and raise an AssertionError. """ openapi_params: Set[Tuple[str, Union[type, Tuple[type, object]]]] = set() - json_params: Dict[str, Union[type, Tuple[type, object]]] = dict() + json_params: Dict[str, Union[type, Tuple[type, object]]] = {} for element in openapi_parameters: name: str = element["name"] schema = {} diff --git a/zerver/tests/test_outgoing_webhook_interfaces.py b/zerver/tests/test_outgoing_webhook_interfaces.py index 6e7640591b..6c4941b47a 100644 --- a/zerver/tests/test_outgoing_webhook_interfaces.py +++ b/zerver/tests/test_outgoing_webhook_interfaces.py @@ -137,7 +137,7 @@ class TestGenericOutgoingWebhookService(ZulipTestCase): ) self.assertEqual(success_response, expected_response) - response = dict() + response = {} success_response = self.handler.process_success(response) self.assertEqual(success_response, None) diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.py index dd1179da14..97305cdf46 100644 --- a/zerver/tests/test_service_bot_system.py +++ b/zerver/tests/test_service_bot_system.py @@ -343,7 +343,7 @@ class TestServiceBotConfigHandler(ZulipTestCase): with self.assertRaises(ConfigError): self.bot_handler.get_config_info('foo') - self.assertEqual(self.bot_handler.get_config_info('foo', optional=True), dict()) + self.assertEqual(self.bot_handler.get_config_info('foo', optional=True), {}) config_dict = {"entry 1": "value 1", "entry 2": "value 2"} for key, value in config_dict.items(): diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 70efbb6b4e..8446cd4fc1 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -759,7 +759,7 @@ class LoginTest(ZulipTestCase): self.assertEqual(response["Location"], "http://zulip.testserver") def test_start_two_factor_auth(self) -> None: - request = MagicMock(POST=dict()) + request = MagicMock(POST={}) with patch('zerver.views.auth.TwoFactorLoginView') as mock_view: mock_view.as_view.return_value = lambda *a, **k: HttpResponse() response = start_two_factor_auth(request) diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py index 1ed3c40983..59027bb10f 100644 --- a/zerver/tests/test_slack_importer.py +++ b/zerver/tests/test_slack_importer.py @@ -627,7 +627,7 @@ class SlackImporter(ZulipTestCase): dm_members = {'DJ47BL849': ('U066MTL5U', 'U061A5N1G'), 'DHX1UP7EG': ('U061A5N1G', 'U061A1R2R')} zerver_usermessage: List[Dict[str, Any]] = [] - subscriber_map: Dict[int, Set[int]] = dict() + subscriber_map: Dict[int, Set[int]] = {} added_channels: Dict[str, Tuple[str, int]] = {'random': ('c5', 1), 'general': ('c6', 2)} zerver_message, zerver_usermessage, attachment, uploads, reaction = \ diff --git a/zerver/tests/test_user_status.py b/zerver/tests/test_user_status.py index 7917a0f64d..455d86d1d6 100644 --- a/zerver/tests/test_user_status.py +++ b/zerver/tests/test_user_status.py @@ -19,7 +19,7 @@ def get_away_user_ids(realm_id: int) -> Set[int]: def user_info(user: UserProfile) -> Dict[str, Any]: user_dict = get_user_info_dict(user.realm_id) - return user_dict.get(str(user.id), dict()) + return user_dict.get(str(user.id), {}) class UserStatusTest(ZulipTestCase): def test_basics(self) -> None: @@ -92,7 +92,7 @@ class UserStatusTest(ZulipTestCase): self.assertEqual( user_info(hamlet), - dict(), + {}, ) away_user_ids = get_away_user_ids(realm_id=realm_id) @@ -148,7 +148,7 @@ class UserStatusTest(ZulipTestCase): self.login_user(hamlet) # Try to omit parameter--this should be an error. - payload: Dict[str, Any] = dict() + payload: Dict[str, Any] = {} result = self.client_post('/json/users/me/status', payload) self.assert_json_error(result, "Client did not pass any new values.") diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py index 19d03f1292..d86363fa56 100644 --- a/zerver/tests/test_users.py +++ b/zerver/tests/test_users.py @@ -768,7 +768,7 @@ class AdminCreateUserTest(ZulipTestCase): self.login_user(admin) do_change_user_role(admin, UserProfile.ROLE_REALM_ADMINISTRATOR) - result = self.client_post("/json/users", dict()) + result = self.client_post("/json/users", {}) self.assert_json_error(result, "Missing 'email' argument") result = self.client_post("/json/users", dict( diff --git a/zerver/tests/test_widgets.py b/zerver/tests/test_widgets.py index 7a89259103..a61e9da800 100644 --- a/zerver/tests/test_widgets.py +++ b/zerver/tests/test_widgets.py @@ -31,7 +31,7 @@ class WidgetContentTestCase(ZulipTestCase): assert_error(dict(widget_type='bogus', extra_data={}), 'unknown widget type: bogus') - extra_data: Dict[str, Any] = dict() + extra_data: Dict[str, Any] = {} obj = dict(widget_type='zform', extra_data=extra_data) assert_error(obj, 'zform is missing type field') diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index ffa8b4228b..e54e51478a 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -687,7 +687,7 @@ def maybe_enqueue_notifications(user_profile_id: int, message_id: int, private_m """This function has a complete unit test suite in `test_enqueue_notifications` that should be expanded as we add more features here.""" - notified: Dict[str, bool] = dict() + notified: Dict[str, bool] = {} if (idle or always_push_notify) and (private_message or mentioned or wildcard_mention_notify or stream_push_notify): diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.py index 927d923832..37ad48897d 100644 --- a/zerver/views/message_fetch.py +++ b/zerver/views/message_fetch.py @@ -1024,7 +1024,7 @@ def get_messages_backend(request: HttpRequest, user_message_flags[message_id] = UserMessage.flags_list_for_flags(flags) message_ids.append(message_id) - search_fields: Dict[int, Dict[str, str]] = dict() + search_fields: Dict[int, Dict[str, str]] = {} if is_search: for row in rows: message_id = row[0] @@ -1231,7 +1231,7 @@ def messages_in_narrow_backend(request: HttpRequest, user_profile: UserProfile, sa_conn = get_sqlalchemy_connection() query_result = list(sa_conn.execute(query).fetchall()) - search_fields = dict() + search_fields = {} for row in query_result: message_id = row['message_id'] topic_name = row[DB_TOPIC_NAME] diff --git a/zerver/views/streams.py b/zerver/views/streams.py index 9d51f940e8..b2937aba3e 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -476,7 +476,7 @@ def add_subscriptions_backend( # We can assume unique emails here for now, but we should eventually # convert this function to be more id-centric. - email_to_user_profile: Dict[str, UserProfile] = dict() + email_to_user_profile: Dict[str, UserProfile] = {} result: Dict[str, Any] = dict(subscribed=defaultdict(list), already_subscribed=defaultdict(list)) for (subscriber, stream) in subscribed: diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.py index 15246d1c56..e0a509392f 100644 --- a/zerver/webhooks/bitbucket3/view.py +++ b/zerver/webhooks/bitbucket3/view.py @@ -51,7 +51,7 @@ PULL_REQUEST_OPENED_OR_MODIFIED_TEMPLATE_WITH_REVIEWERS_WITH_TITLE = """ def fixture_to_headers(fixture_name: str) -> Dict[str, str]: if fixture_name == "diagnostics_ping": return {"HTTP_X_EVENT_KEY": "diagnostics:ping"} - return dict() + return {} def get_user_name(payload: Dict[str, Any]) -> str: user_name = "[{name}]({url})".format(name=payload["actor"]["name"], diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 1ed8503453..5ea2a7ae3d 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -715,7 +715,7 @@ def generate_and_send_messages(data: Tuple[int, Sequence[Sequence[int]], Mapping Subscription.objects.filter(recipient_id=h)] # Generate different topics for each stream - possible_topics = dict() + possible_topics = {} for stream_id in recipient_streams: possible_topics[stream_id] = generate_topics(options["max_topics"])