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

@@ -1,10 +1,11 @@
import logging
from argparse import ArgumentParser
from typing import Any, Collection
from typing import Any
from django.conf import settings
from django.core.management.base import CommandError
from django.db import transaction
from django.db.models import QuerySet
from typing_extensions import override
from zerver.lib.logging_util import log_to_file
@@ -20,7 +21,7 @@ log_to_file(logger, settings.LDAP_SYNC_LOG_PATH)
# Run this on a cron job to pick up on name changes.
@transaction.atomic
def sync_ldap_user_data(
user_profiles: Collection[UserProfile], deactivation_protection: bool = True
user_profiles: QuerySet[UserProfile], deactivation_protection: bool = True
) -> None:
logger.info("Starting update.")
try: