python: Avoid relying on Collection supertype of QuerySet.

QuerySet doesn’t implement __contains__, so it can’t be a subtype of
Container or Collection (https://code.djangoproject.com/ticket/35154).
This incorrect subtyping annotation was removed in
https://github.com/typeddjango/django-stubs/pull/1925, so we need to
stop relying on it before upgrading to django-stubs 5.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-04-16 20:28:33 -07:00
committed by Tim Abbott
parent 5654d051f7
commit f31579a220
9 changed files with 28 additions and 24 deletions

View File

@@ -7,7 +7,7 @@ from typing import Any, Collection, Dict, Iterator, List, Optional, Set, Tuple
from django.conf import settings
from django.db import transaction
from django.db.models import Exists, OuterRef
from django.db.models import Exists, OuterRef, QuerySet
from django.utils.timezone import now as timezone_now
from django.utils.translation import gettext as _
from typing_extensions import TypeAlias
@@ -331,7 +331,7 @@ def get_slim_stream_id_map(realm: Realm) -> Dict[int, Stream]:
def bulk_get_digest_context(
users: Collection[UserProfile], cutoff: float
users: Collection[UserProfile] | QuerySet[UserProfile], cutoff: float
) -> Iterator[Tuple[UserProfile, Dict[str, Any]]]:
# We expect a non-empty list of users all from the same realm.
assert users