typing: Use accurate type hints for dictionaries.

This fixes the mypy errors related to dictionaries with django-stubs.
This commit is contained in:
PIG208 2021-08-03 23:44:55 +08:00 committed by Tim Abbott
parent 3b11c36ed9
commit 7386918539
3 changed files with 5 additions and 5 deletions

View File

@ -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}

View File

@ -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,
}

View File

@ -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": (