From 738691853946bb10ee3a4b0dc6e2f602818609fc Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Tue, 3 Aug 2021 23:44:55 +0800 Subject: [PATCH] typing: Use accurate type hints for dictionaries. This fixes the mypy errors related to dictionaries with django-stubs. --- analytics/lib/counts.py | 2 +- corporate/lib/stripe.py | 4 ++-- zerver/lib/cache_helpers.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/analytics/lib/counts.py b/analytics/lib/counts.py index 761eaf094e..e2ca1ba600 100644 --- a/analytics/lib/counts.py +++ b/analytics/lib/counts.py @@ -302,7 +302,7 @@ def do_increment_logging_stat( table = stat.data_collector.output_table if table == RealmCount: assert isinstance(zerver_object, Realm) - id_args = {"realm": zerver_object} + id_args: Dict[str, Union[Realm, UserProfile, Stream]] = {"realm": zerver_object} elif table == UserCount: assert isinstance(zerver_object, UserProfile) id_args = {"realm": zerver_object.realm, "user": zerver_object} diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 5df0c9fbf7..f5b28807cb 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -5,7 +5,7 @@ import secrets from datetime import datetime, timedelta from decimal import Decimal from functools import wraps -from typing import Any, Callable, Dict, Generator, Optional, Tuple, TypeVar, cast +from typing import Any, Callable, Dict, Generator, Optional, Tuple, TypeVar, Union, cast import orjson import stripe @@ -1032,7 +1032,7 @@ def downgrade_small_realms_behind_on_payments_as_needed() -> None: downgrade_now_without_creating_additional_invoices(realm) void_all_open_invoices(realm) - context: Dict[str, str] = { + context: Dict[str, Union[str, Realm]] = { "upgrade_url": f"{realm.uri}{reverse('initial_upgrade')}", "realm": realm, } diff --git a/zerver/lib/cache_helpers.py b/zerver/lib/cache_helpers.py index 04439b0552..405fd61a89 100644 --- a/zerver/lib/cache_helpers.py +++ b/zerver/lib/cache_helpers.py @@ -1,7 +1,7 @@ # See https://zulip.readthedocs.io/en/latest/subsystems/caching.html for docs import datetime import logging -from typing import Any, Callable, Dict, List, Tuple +from typing import Any, Callable, Dict, Iterable, List, Tuple from django.conf import settings from django.contrib.sessions.models import Session @@ -106,7 +106,7 @@ def get_users() -> List[UserProfile]: # wrapper the below adds an extra 3ms or so to startup time for # anything importing this file). cache_fillers: Dict[ - str, Tuple[Callable[[], List[Any]], Callable[[Dict[str, Any], Any], None], int, int] + str, Tuple[Callable[[], Iterable[Any]], Callable[[Dict[str, Any], Any], None], int, int] ] = { "user": (get_users, user_cache_items, 3600 * 24 * 7, 10000), "client": (