From d3efd4c095f76385b39db6f02dbd33316de10f90 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 3 Mar 2023 16:52:14 -0800 Subject: [PATCH] python: Import F, Q, QuerySet from their canonical module. Signed-off-by: Anders Kaseorg --- analytics/views/realm_activity.py | 2 +- analytics/views/stats.py | 2 +- analytics/views/user_activity.py | 2 +- zerver/actions/realm_settings.py | 2 +- zerver/lib/bot_config.py | 3 +-- zerver/lib/bot_storage.py | 3 +-- zerver/lib/cache.py | 3 +-- zerver/lib/cache_helpers.py | 2 +- zerver/lib/soft_deactivation.py | 3 +-- zerver/lib/streams.py | 3 +-- zerver/lib/subscription_info.py | 2 +- zerver/lib/topic.py | 2 +- zerver/lib/user_topics.py | 2 +- zerver/lib/users.py | 2 +- zerver/management/commands/soft_deactivate_users.py | 2 +- zerver/models.py | 3 +-- zerver/tests/test_import_export.py | 3 +-- 17 files changed, 17 insertions(+), 24 deletions(-) diff --git a/analytics/views/realm_activity.py b/analytics/views/realm_activity.py index 674e5ca79c..519131a650 100644 --- a/analytics/views/realm_activity.py +++ b/analytics/views/realm_activity.py @@ -3,7 +3,7 @@ from datetime import datetime from typing import Any, Dict, List, Optional, Set, Tuple from django.db import connection -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.http import HttpRequest, HttpResponse, HttpResponseNotFound from django.shortcuts import render from django.utils.timezone import now as timezone_now diff --git a/analytics/views/stats.py b/analytics/views/stats.py index 2e9744ba58..cf05e23624 100644 --- a/analytics/views/stats.py +++ b/analytics/views/stats.py @@ -4,7 +4,7 @@ from datetime import datetime, timedelta, timezone from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar, Union, cast from django.conf import settings -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.http import HttpRequest, HttpResponse, HttpResponseNotFound from django.shortcuts import render from django.utils import translation diff --git a/analytics/views/user_activity.py b/analytics/views/user_activity.py index 43d1d5e1d2..012320b66c 100644 --- a/analytics/views/user_activity.py +++ b/analytics/views/user_activity.py @@ -1,7 +1,7 @@ from typing import Any, Dict, List, Tuple from django.conf import settings -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.http import HttpRequest, HttpResponse from django.shortcuts import render diff --git a/zerver/actions/realm_settings.py b/zerver/actions/realm_settings.py index 3f2ff9fd53..7ababffee4 100644 --- a/zerver/actions/realm_settings.py +++ b/zerver/actions/realm_settings.py @@ -5,7 +5,7 @@ from typing import Any, Dict, Literal, Optional, Tuple, Union import orjson from django.conf import settings from django.db import transaction -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.utils.timezone import now as timezone_now from confirmation.models import Confirmation, create_confirmation_link, generate_key diff --git a/zerver/lib/bot_config.py b/zerver/lib/bot_config.py index 00d4429ede..d1097e05e6 100644 --- a/zerver/lib/bot_config.py +++ b/zerver/lib/bot_config.py @@ -5,9 +5,8 @@ from collections import defaultdict from typing import Dict, List, Optional from django.conf import settings -from django.db.models import Sum +from django.db.models import F, Sum from django.db.models.functions import Length -from django.db.models.query import F from zerver.models import BotConfigData, UserProfile diff --git a/zerver/lib/bot_storage.py b/zerver/lib/bot_storage.py index cdef798406..7b3a9163da 100644 --- a/zerver/lib/bot_storage.py +++ b/zerver/lib/bot_storage.py @@ -1,9 +1,8 @@ from typing import List, Optional, Tuple from django.conf import settings -from django.db.models import Sum +from django.db.models import F, Sum from django.db.models.functions import Length -from django.db.models.query import F from zerver.models import BotStorageData, UserProfile diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 4f31345dca..7bb040a9c2 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -25,8 +25,7 @@ from typing import ( from django.conf import settings from django.core.cache import caches from django.core.cache.backends.base import BaseCache -from django.db.models import Q -from django.db.models.query import QuerySet +from django.db.models import Q, QuerySet from django.http import HttpRequest from typing_extensions import ParamSpec diff --git a/zerver/lib/cache_helpers.py b/zerver/lib/cache_helpers.py index 8a923f7830..009a2bbf0d 100644 --- a/zerver/lib/cache_helpers.py +++ b/zerver/lib/cache_helpers.py @@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Iterable, Tuple from django.conf import settings from django.contrib.sessions.models import Session -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.utils.timezone import now as timezone_now from django_stubs_ext import ValuesQuerySet diff --git a/zerver/lib/soft_deactivation.py b/zerver/lib/soft_deactivation.py index 04dc294c3e..f6628ba153 100644 --- a/zerver/lib/soft_deactivation.py +++ b/zerver/lib/soft_deactivation.py @@ -5,8 +5,7 @@ from typing import Any, DefaultDict, Dict, Iterable, List, Optional, Sequence, S from django.conf import settings from django.db import transaction -from django.db.models import Max -from django.db.models.query import QuerySet +from django.db.models import Max, QuerySet from django.utils.timezone import now as timezone_now from sentry_sdk import capture_exception diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index c2788b19ae..7244d5c9fe 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -1,8 +1,7 @@ from typing import Collection, List, Optional, Set, Tuple, TypedDict, Union from django.db import transaction -from django.db.models import Exists, OuterRef, Q -from django.db.models.query import QuerySet +from django.db.models import Exists, OuterRef, Q, QuerySet from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ diff --git a/zerver/lib/subscription_info.py b/zerver/lib/subscription_info.py index e20ac9c94b..5f753f9323 100644 --- a/zerver/lib/subscription_info.py +++ b/zerver/lib/subscription_info.py @@ -4,7 +4,7 @@ from typing import Any, Callable, Collection, Dict, Iterable, List, Mapping, Opt from django.core.exceptions import ValidationError from django.db import connection -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.utils.translation import gettext as _ from psycopg2.sql import SQL diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py index 3f846ab77b..5908e13080 100644 --- a/zerver/lib/topic.py +++ b/zerver/lib/topic.py @@ -3,7 +3,7 @@ from typing import Any, Dict, List, Optional, Tuple import orjson from django.db import connection -from django.db.models.query import Q, QuerySet +from django.db.models import Q, QuerySet from sqlalchemy.sql import ColumnElement, column, func, literal from sqlalchemy.types import Boolean, Text diff --git a/zerver/lib/user_topics.py b/zerver/lib/user_topics.py index 48c75fdb99..be8b086c95 100644 --- a/zerver/lib/user_topics.py +++ b/zerver/lib/user_topics.py @@ -1,7 +1,7 @@ import datetime from typing import Callable, List, Optional, Tuple, TypedDict -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.utils.timezone import now as timezone_now from sqlalchemy.sql import ClauseElement, and_, column, not_, or_ from sqlalchemy.types import Integer diff --git a/zerver/lib/users.py b/zerver/lib/users.py index 5f2a7087fc..ebcd8e15d8 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -6,7 +6,7 @@ from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Typed import dateutil.parser as date_parser from django.conf import settings from django.core.exceptions import ValidationError -from django.db.models.query import QuerySet +from django.db.models import QuerySet from django.forms.models import model_to_dict from django.utils.translation import gettext as _ from django_otp.middleware import is_verified diff --git a/zerver/management/commands/soft_deactivate_users.py b/zerver/management/commands/soft_deactivate_users.py index b62d5238de..dc798a5154 100644 --- a/zerver/management/commands/soft_deactivate_users.py +++ b/zerver/management/commands/soft_deactivate_users.py @@ -4,7 +4,7 @@ from typing import Any, Dict, List from django.conf import settings from django.core.management.base import CommandError -from django.db.models.query import QuerySet +from django.db.models import QuerySet from zerver.lib.management import ZulipBaseCommand from zerver.lib.soft_deactivation import ( diff --git a/zerver/models.py b/zerver/models.py index 5b6942cb15..3cdcedba76 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -42,9 +42,8 @@ from django.core.exceptions import ValidationError from django.core.validators import MinLengthValidator, RegexValidator, URLValidator, validate_email from django.db import models, transaction from django.db.backends.base.base import BaseDatabaseWrapper -from django.db.models import CASCADE, Exists, F, OuterRef, Q, Sum +from django.db.models import CASCADE, Exists, F, OuterRef, Q, QuerySet, Sum from django.db.models.functions import Lower, Upper -from django.db.models.query import QuerySet from django.db.models.signals import post_delete, post_save, pre_delete from django.db.models.sql.compiler import SQLCompiler from django.utils.timezone import now as timezone_now diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index 6c0103b44d..e0d534c03b 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -7,8 +7,7 @@ from unittest.mock import patch import orjson from django.conf import settings from django.core.exceptions import ValidationError -from django.db.models import Q -from django.db.models.query import QuerySet +from django.db.models import Q, QuerySet from django.utils.timezone import now as timezone_now from analytics.models import UserCount