diff --git a/analytics/lib/counts.py b/analytics/lib/counts.py index 41b52e0087..437d7d7c4f 100644 --- a/analytics/lib/counts.py +++ b/analytics/lib/counts.py @@ -1,13 +1,14 @@ import logging import time from collections import OrderedDict, defaultdict +from collections.abc import Callable, Sequence from datetime import datetime, timedelta -from typing import Callable, Sequence, Union +from typing import TypeAlias, Union from django.conf import settings from django.db import connection, models from psycopg2.sql import SQL, Composable, Identifier, Literal -from typing_extensions import TypeAlias, override +from typing_extensions import override from analytics.models import ( BaseCount, diff --git a/analytics/management/commands/populate_analytics_db.py b/analytics/management/commands/populate_analytics_db.py index 47806fc2e5..1bf003c900 100644 --- a/analytics/management/commands/populate_analytics_db.py +++ b/analytics/management/commands/populate_analytics_db.py @@ -1,9 +1,10 @@ +from collections.abc import Mapping from datetime import timedelta -from typing import Any, Mapping +from typing import Any, TypeAlias from django.core.files.uploadedfile import UploadedFile from django.utils.timezone import now as timezone_now -from typing_extensions import TypeAlias, override +from typing_extensions import override from analytics.lib.counts import COUNT_STATS, CountStat, do_drop_all_analytics_tables from analytics.lib.fixtures import generate_time_series_data diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.py index 42efed5456..8434fee305 100644 --- a/analytics/tests/test_counts.py +++ b/analytics/tests/test_counts.py @@ -1,6 +1,7 @@ +from collections.abc import Iterator from contextlib import AbstractContextManager, ExitStack, contextmanager from datetime import datetime, timedelta, timezone -from typing import Any, Iterator +from typing import Any from unittest import mock import time_machine diff --git a/analytics/views/stats.py b/analytics/views/stats.py index ec656be10c..0ef6f6a153 100644 --- a/analytics/views/stats.py +++ b/analytics/views/stats.py @@ -1,7 +1,7 @@ import logging from collections import defaultdict from datetime import datetime, timedelta, timezone -from typing import Any, Optional, TypeVar, cast +from typing import Any, Optional, TypeAlias, TypeVar, cast from django.conf import settings from django.db.models import QuerySet @@ -10,7 +10,6 @@ from django.shortcuts import render from django.utils import translation from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ -from typing_extensions import TypeAlias from analytics.lib.counts import COUNT_STATS, CountStat from analytics.lib.time_utils import time_range diff --git a/confirmation/models.py b/confirmation/models.py index 7c976fc5c9..8beea4b7e1 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -3,8 +3,9 @@ __revision__ = "$Id: models.py 28 2009-10-22 15:03:02Z jarek.zgoda $" import secrets from base64 import b32encode +from collections.abc import Mapping from datetime import timedelta -from typing import Mapping, Optional, Union, cast +from typing import Optional, TypeAlias, Union, cast from urllib.parse import urljoin from django.conf import settings @@ -16,7 +17,7 @@ from django.http import HttpRequest, HttpResponse from django.template.response import TemplateResponse from django.urls import reverse from django.utils.timezone import now as timezone_now -from typing_extensions import TypeAlias, override +from typing_extensions import override from confirmation import settings as confirmation_settings from zerver.lib.types import UnspecifiedValue diff --git a/corporate/lib/activity.py b/corporate/lib/activity.py index e377eae592..7b3603baf7 100644 --- a/corporate/lib/activity.py +++ b/corporate/lib/activity.py @@ -1,8 +1,9 @@ from collections import defaultdict +from collections.abc import Callable, Sequence from dataclasses import dataclass from datetime import datetime from decimal import Decimal -from typing import Any, Callable, Sequence +from typing import Any from urllib.parse import urlencode from django.conf import settings diff --git a/corporate/lib/decorator.py b/corporate/lib/decorator.py index 178453c218..3f4dc53b89 100644 --- a/corporate/lib/decorator.py +++ b/corporate/lib/decorator.py @@ -1,12 +1,13 @@ +from collections.abc import Callable from functools import wraps -from typing import Callable +from typing import Concatenate from urllib.parse import urlencode, urljoin from django.conf import settings from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import render from django.urls import reverse -from typing_extensions import Concatenate, ParamSpec +from typing_extensions import ParamSpec from corporate.lib.remote_billing_util import ( RemoteBillingIdentityExpiredError, diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 7fdab1d796..b1ddce9314 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -3,12 +3,13 @@ import math import os import secrets from abc import ABC, abstractmethod +from collections.abc import Callable, Generator from dataclasses import dataclass from datetime import datetime, timedelta, timezone from decimal import Decimal from enum import Enum from functools import wraps -from typing import Any, Callable, Generator, Literal, TypedDict, TypeVar +from typing import Any, Literal, TypedDict, TypeVar from urllib.parse import urlencode, urljoin import stripe diff --git a/corporate/lib/stripe_event_handler.py b/corporate/lib/stripe_event_handler.py index 026255288a..dd6e0a8971 100644 --- a/corporate/lib/stripe_event_handler.py +++ b/corporate/lib/stripe_event_handler.py @@ -1,5 +1,6 @@ import logging -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import stripe from django.conf import settings diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 7150de0039..32d443f43c 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -6,11 +6,12 @@ import re import sys import typing import uuid +from collections.abc import Callable, Mapping, Sequence from dataclasses import dataclass from datetime import datetime, timedelta, timezone from decimal import Decimal from functools import wraps -from typing import TYPE_CHECKING, Any, Callable, Literal, Mapping, Optional, Sequence, TypeVar, cast +from typing import TYPE_CHECKING, Any, Literal, Optional, TypeVar, cast from unittest import mock from unittest.mock import MagicMock, Mock, patch diff --git a/corporate/views/billing_page.py b/corporate/views/billing_page.py index b59bbc8673..1c4a5abd00 100644 --- a/corporate/views/billing_page.py +++ b/corporate/views/billing_page.py @@ -1,12 +1,11 @@ import logging -from typing import Any, Literal +from typing import Annotated, Any, Literal from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed, HttpResponseRedirect from django.shortcuts import render from django.urls import reverse from django.utils.translation import gettext as _ from pydantic import AfterValidator, Json -from typing_extensions import Annotated from corporate.lib.decorator import ( authenticated_remote_realm_management_endpoint, diff --git a/corporate/views/realm_activity.py b/corporate/views/realm_activity.py index 84840b92da..f3896ad140 100644 --- a/corporate/views/realm_activity.py +++ b/corporate/views/realm_activity.py @@ -1,8 +1,9 @@ import itertools import re +from collections.abc import Collection from dataclasses import dataclass from datetime import datetime -from typing import Any, Collection +from typing import Any from django.db.models import QuerySet from django.http import HttpRequest, HttpResponse, HttpResponseNotFound diff --git a/corporate/views/remote_billing_page.py b/corporate/views/remote_billing_page.py index 4f34b5b408..77a9eec346 100644 --- a/corporate/views/remote_billing_page.py +++ b/corporate/views/remote_billing_page.py @@ -1,5 +1,5 @@ import logging -from typing import Any, Literal, cast +from typing import Any, Literal, TypeAlias, cast from urllib.parse import urlsplit, urlunsplit from django.conf import settings @@ -15,7 +15,6 @@ from django.utils.translation import get_language from django.utils.translation import gettext as _ from django.views.decorators.csrf import csrf_exempt from pydantic import Json -from typing_extensions import TypeAlias from confirmation.models import ( Confirmation, diff --git a/corporate/views/support.py b/corporate/views/support.py index 7dd3e6e6ab..ad8624960b 100644 --- a/corporate/views/support.py +++ b/corporate/views/support.py @@ -1,9 +1,10 @@ import uuid +from collections.abc import Iterable from contextlib import suppress from dataclasses import dataclass from datetime import timedelta from operator import attrgetter -from typing import Any, Iterable +from typing import Annotated, Any, Literal from urllib.parse import urlencode, urlsplit from django import forms @@ -18,7 +19,6 @@ from django.utils.timesince import timesince from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from pydantic import AfterValidator, Json, NonNegativeInt -from typing_extensions import Annotated, Literal from confirmation.models import Confirmation, confirmation_url from confirmation.settings import STATUS_USED diff --git a/corporate/views/upgrade.py b/corporate/views/upgrade.py index 84dcc56950..7b74a34dd9 100644 --- a/corporate/views/upgrade.py +++ b/corporate/views/upgrade.py @@ -1,10 +1,10 @@ import logging +from typing import Annotated from django.conf import settings from django.http import HttpRequest, HttpResponse, HttpResponseRedirect from django.shortcuts import render from pydantic import AfterValidator, Json -from typing_extensions import Annotated from corporate.lib.decorator import ( authenticated_remote_realm_management_endpoint, diff --git a/puppet/kandra/files/memcached_exporter b/puppet/kandra/files/memcached_exporter index b2d0b7a846..43eb3ddc88 100755 --- a/puppet/kandra/files/memcached_exporter +++ b/puppet/kandra/files/memcached_exporter @@ -3,7 +3,8 @@ import contextlib import sys import time -from typing import Any, Iterable, Sequence +from collections.abc import Iterable, Sequence +from typing import Any sys.path.append("/home/zulip/deployments/current") from scripts.lib.setup_path import setup_path diff --git a/puppet/zulip/files/postgresql/wal-g-exporter b/puppet/zulip/files/postgresql/wal-g-exporter index 280c047fae..681dc404a7 100755 --- a/puppet/zulip/files/postgresql/wal-g-exporter +++ b/puppet/zulip/files/postgresql/wal-g-exporter @@ -7,9 +7,10 @@ import os import subprocess import sys from collections import defaultdict +from collections.abc import Mapping from datetime import datetime, timedelta, timezone from http.server import BaseHTTPRequestHandler, HTTPServer -from typing import Mapping, Protocol +from typing import Protocol from urllib.parse import parse_qs, urlsplit diff --git a/scripts/lib/hash_reqs.py b/scripts/lib/hash_reqs.py index 65b0024fae..7e01f5e64f 100755 --- a/scripts/lib/hash_reqs.py +++ b/scripts/lib/hash_reqs.py @@ -4,7 +4,7 @@ import hashlib import os import subprocess import sys -from typing import Iterable +from collections.abc import Iterable def expand_reqs_helper(fpath: str) -> list[str]: diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index d65c00b889..24a4828df0 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -15,8 +15,9 @@ import subprocess import sys import time import uuid +from collections.abc import Sequence from datetime import datetime, timedelta -from typing import IO, Any, Literal, Sequence, overload +from typing import IO, Any, Literal, overload from urllib.parse import SplitResult import zoneinfo diff --git a/scripts/log-search b/scripts/log-search index 351888890b..0624a6698b 100755 --- a/scripts/log-search +++ b/scripts/log-search @@ -10,7 +10,8 @@ import signal import sys from datetime import date, datetime, timedelta, timezone from enum import Enum, auto -from typing import Match, TextIO +from re import Match +from typing import TextIO ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(ZULIP_PATH) diff --git a/tools/check-schemas b/tools/check-schemas index c3b7da2ddb..0b890008cd 100755 --- a/tools/check-schemas +++ b/tools/check-schemas @@ -14,7 +14,8 @@ import difflib import os import subprocess import sys -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import orjson diff --git a/tools/check-templates b/tools/check-templates index 19d09539b9..5f5a2da570 100755 --- a/tools/check-templates +++ b/tools/check-templates @@ -11,7 +11,7 @@ from tools.lib import sanity_check sanity_check.check_venv(__file__) -from typing import Iterable +from collections.abc import Iterable from zulint import lister diff --git a/tools/diagnose b/tools/diagnose index b805a29978..79d3414542 100755 --- a/tools/diagnose +++ b/tools/diagnose @@ -4,7 +4,7 @@ import platform import shlex import subprocess import sys -from typing import Callable +from collections.abc import Callable TOOLS_DIR = os.path.dirname(__file__) ROOT_DIR = os.path.dirname(TOOLS_DIR) diff --git a/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py b/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py index ded0da2cf4..2654e0acf5 100644 --- a/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py +++ b/tools/documentation_crawler/documentation_crawler/spiders/common/spiders.py @@ -1,7 +1,7 @@ import json import os import re -from typing import Callable, Iterator +from collections.abc import Callable, Iterator from urllib.parse import urlsplit import scrapy diff --git a/tools/lib/capitalization.py b/tools/lib/capitalization.py index ccfe6b5a1b..8fe97f93a1 100644 --- a/tools/lib/capitalization.py +++ b/tools/lib/capitalization.py @@ -1,5 +1,5 @@ import re -from typing import Match +from re import Match from bs4 import BeautifulSoup diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py index ff49cb874b..4a93165d0f 100644 --- a/tools/lib/template_parser.py +++ b/tools/lib/template_parser.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from typing_extensions import override diff --git a/tools/lib/test_script.py b/tools/lib/test_script.py index c558cebbe9..bd0415a6f1 100644 --- a/tools/lib/test_script.py +++ b/tools/lib/test_script.py @@ -3,7 +3,7 @@ import os import subprocess import sys from argparse import ArgumentParser -from typing import Iterable +from collections.abc import Iterable from scripts.lib.zulip_tools import get_dev_uuid_var_path from version import PROVISION_VERSION diff --git a/tools/lib/test_server.py b/tools/lib/test_server.py index 6675a05e1b..f51e2c0c00 100644 --- a/tools/lib/test_server.py +++ b/tools/lib/test_server.py @@ -2,8 +2,8 @@ import os import subprocess import sys import time +from collections.abc import Iterator from contextlib import ExitStack, contextmanager -from typing import Iterator # Verify the Zulip venv is available. from tools.lib import sanity_check diff --git a/tools/semgrep-py.yml b/tools/semgrep-py.yml index d3fb6b352d..4f812a658c 100644 --- a/tools/semgrep-py.yml +++ b/tools/semgrep-py.yml @@ -279,10 +279,10 @@ rules: def $F(..., invalid_param: typing.Optional[<... zerver.lib.typed_endpoint.ApiParamConfig(...) ...>], ...) -> ...: ... - pattern-not: | - def $F(..., $A: typing_extensions.Annotated[<... zerver.lib.typed_endpoint.ApiParamConfig(...) ...>], ...) -> ...: + def $F(..., $A: typing.Annotated[<... zerver.lib.typed_endpoint.ApiParamConfig(...) ...>], ...) -> ...: ... - pattern-not: | - def $F(..., $A: typing_extensions.Annotated[<... zerver.lib.typed_endpoint.ApiParamConfig(...) ...>] = ..., ...) -> ...: + def $F(..., $A: typing.Annotated[<... zerver.lib.typed_endpoint.ApiParamConfig(...) ...>] = ..., ...) -> ...: ... - pattern-either: - pattern: | diff --git a/tools/setup/emoji/build_emoji b/tools/setup/emoji/build_emoji index ad7e1fc66b..08cbd39897 100755 --- a/tools/setup/emoji/build_emoji +++ b/tools/setup/emoji/build_emoji @@ -5,7 +5,8 @@ import os import shutil import sys -from typing import Any, Iterator, Sequence +from collections.abc import Iterator, Sequence +from typing import Any import orjson diff --git a/tools/tail-ses b/tools/tail-ses index ada0f30643..6899dfbbea 100755 --- a/tools/tail-ses +++ b/tools/tail-ses @@ -12,8 +12,9 @@ setup_path() os.environ["DJANGO_SETTINGS_MODULE"] = "zproject.settings" import argparse import secrets +from collections.abc import Iterator from contextlib import contextmanager -from typing import Iterator, TypedDict +from typing import TypedDict import boto3.session import orjson diff --git a/tools/test-backend b/tools/test-backend index fa0e81decb..b2ea702b47 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -8,7 +8,8 @@ import shlex import subprocess import sys import tempfile -from typing import TYPE_CHECKING, Iterator, cast +from collections.abc import Iterator +from typing import TYPE_CHECKING, cast from unittest import mock if TYPE_CHECKING: diff --git a/tools/test-documentation b/tools/test-documentation index fb668a6605..30d5a3bf27 100755 --- a/tools/test-documentation +++ b/tools/test-documentation @@ -3,7 +3,7 @@ import argparse import os import subprocess import sys -from typing import Sequence +from collections.abc import Sequence ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.chdir(ZULIP_PATH) diff --git a/tools/test-help-documentation b/tools/test-help-documentation index baf1b25446..bfc76e95c4 100755 --- a/tools/test-help-documentation +++ b/tools/test-help-documentation @@ -4,7 +4,7 @@ import contextlib import os import subprocess import sys -from typing import Iterator +from collections.abc import Iterator ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.chdir(ZULIP_PATH) diff --git a/tools/test-js-with-puppeteer b/tools/test-js-with-puppeteer index 8f8e4533f3..4bfec91204 100755 --- a/tools/test-js-with-puppeteer +++ b/tools/test-js-with-puppeteer @@ -39,7 +39,7 @@ from tools.lib import sanity_check sanity_check.check_venv(__file__) -from typing import Iterable +from collections.abc import Iterable from tools.lib.test_script import ( add_provision_check_override_param, diff --git a/zerver/actions/alert_words.py b/zerver/actions/alert_words.py index aca81a8b3c..a9202873dc 100644 --- a/zerver/actions/alert_words.py +++ b/zerver/actions/alert_words.py @@ -1,4 +1,4 @@ -from typing import Iterable, Sequence +from collections.abc import Iterable, Sequence from zerver.lib.alert_words import add_user_alert_words, remove_user_alert_words from zerver.models import UserProfile diff --git a/zerver/actions/create_user.py b/zerver/actions/create_user.py index 20dba8ed89..034b0f4aa0 100644 --- a/zerver/actions/create_user.py +++ b/zerver/actions/create_user.py @@ -1,6 +1,7 @@ from collections import defaultdict +from collections.abc import Iterable, Sequence from datetime import timedelta -from typing import Any, Iterable, Sequence +from typing import Any from django.conf import settings from django.db import transaction diff --git a/zerver/actions/custom_profile_fields.py b/zerver/actions/custom_profile_fields.py index b99763c04b..6c7e338a9c 100644 --- a/zerver/actions/custom_profile_fields.py +++ b/zerver/actions/custom_profile_fields.py @@ -1,4 +1,4 @@ -from typing import Iterable +from collections.abc import Iterable import orjson from django.db import transaction diff --git a/zerver/actions/default_streams.py b/zerver/actions/default_streams.py index dc90d10f56..9f5cc0355b 100644 --- a/zerver/actions/default_streams.py +++ b/zerver/actions/default_streams.py @@ -1,4 +1,5 @@ -from typing import Any, Iterable +from collections.abc import Iterable +from typing import Any from django.db import transaction from django.utils.translation import gettext as _ diff --git a/zerver/actions/invites.py b/zerver/actions/invites.py index 8a5feb0d0b..9f66f04a01 100644 --- a/zerver/actions/invites.py +++ b/zerver/actions/invites.py @@ -1,6 +1,7 @@ import logging +from collections.abc import Collection, Sequence from datetime import datetime, timedelta -from typing import Any, Collection, Sequence +from typing import Any from django.conf import settings from django.contrib.contenttypes.models import ContentType diff --git a/zerver/actions/message_delete.py b/zerver/actions/message_delete.py index c7ce3ef6ba..7ccc754a27 100644 --- a/zerver/actions/message_delete.py +++ b/zerver/actions/message_delete.py @@ -1,4 +1,5 @@ -from typing import Iterable, TypedDict +from collections.abc import Iterable +from typing import TypedDict from zerver.lib import retention from zerver.lib.retention import move_messages_to_archive diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py index 463629a67d..4002372680 100644 --- a/zerver/actions/message_edit.py +++ b/zerver/actions/message_edit.py @@ -1,7 +1,9 @@ import itertools from collections import defaultdict +from collections.abc import Iterable +from collections.abc import Set as AbstractSet from datetime import timedelta -from typing import AbstractSet, Any, Iterable +from typing import Any from django.conf import settings from django.db import transaction diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py index c87b72032a..37148f1296 100644 --- a/zerver/actions/message_send.py +++ b/zerver/actions/message_send.py @@ -1,9 +1,11 @@ import logging from collections import defaultdict +from collections.abc import Callable, Collection, Sequence +from collections.abc import Set as AbstractSet from dataclasses import dataclass from datetime import timedelta from email.headerregistry import Address -from typing import AbstractSet, Any, Callable, Collection, Sequence, TypedDict +from typing import Any, TypedDict import orjson from django.conf import settings diff --git a/zerver/actions/scheduled_messages.py b/zerver/actions/scheduled_messages.py index 093d66d555..ab9239d90a 100644 --- a/zerver/actions/scheduled_messages.py +++ b/zerver/actions/scheduled_messages.py @@ -1,6 +1,6 @@ import logging +from collections.abc import Sequence from datetime import datetime, timedelta -from typing import Sequence from django.conf import settings from django.db import transaction diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py index 17752c4e10..dbfa622365 100644 --- a/zerver/actions/streams.py +++ b/zerver/actions/streams.py @@ -1,6 +1,7 @@ import hashlib from collections import defaultdict -from typing import Any, Collection, Iterable, Mapping +from collections.abc import Collection, Iterable, Mapping +from typing import Any, TypeAlias from django.conf import settings from django.db import transaction @@ -9,7 +10,6 @@ from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from django.utils.translation import override as override_language from django_stubs_ext import ValuesQuerySet -from typing_extensions import TypeAlias from zerver.actions.default_streams import ( do_remove_default_stream, diff --git a/zerver/actions/user_groups.py b/zerver/actions/user_groups.py index 3100599107..e402aea84d 100644 --- a/zerver/actions/user_groups.py +++ b/zerver/actions/user_groups.py @@ -1,5 +1,6 @@ +from collections.abc import Mapping, Sequence from datetime import datetime -from typing import Mapping, Sequence, TypedDict +from typing import TypedDict import django.db.utils from django.db import transaction diff --git a/zerver/actions/user_settings.py b/zerver/actions/user_settings.py index c796af6bf7..1aca5c0ea4 100644 --- a/zerver/actions/user_settings.py +++ b/zerver/actions/user_settings.py @@ -1,5 +1,5 @@ +from collections.abc import Iterable from datetime import timedelta -from typing import Iterable from django.conf import settings from django.db import transaction diff --git a/zerver/context_processors.py b/zerver/context_processors.py index 27845ad6a1..a4f48e1cc8 100644 --- a/zerver/context_processors.py +++ b/zerver/context_processors.py @@ -1,4 +1,5 @@ -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from urllib.parse import urljoin from django.conf import settings diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py index d5342e21a1..b0cdeada91 100644 --- a/zerver/data_import/import_util.py +++ b/zerver/data_import/import_util.py @@ -3,14 +3,15 @@ import os import random import shutil from collections import defaultdict +from collections.abc import Callable, Iterable, Iterator, Mapping +from collections.abc import Set as AbstractSet from concurrent.futures import ProcessPoolExecutor, as_completed -from typing import AbstractSet, Any, Callable, Iterable, Iterator, Mapping, Protocol, TypeVar +from typing import Any, Protocol, TypeAlias, TypeVar import orjson import requests from django.forms.models import model_to_dict from django.utils.timezone import now as timezone_now -from typing_extensions import TypeAlias from zerver.data_import.sequencer import NEXT_ID from zerver.lib.avatar_hash import user_avatar_base_path_from_ids diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py index d7df1f898e..3dee8d4209 100644 --- a/zerver/data_import/mattermost.py +++ b/zerver/data_import/mattermost.py @@ -10,7 +10,8 @@ import re import secrets import shutil import subprocess -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import orjson from django.conf import settings diff --git a/zerver/data_import/sequencer.py b/zerver/data_import/sequencer.py index d50189613c..78a734e6c5 100644 --- a/zerver/data_import/sequencer.py +++ b/zerver/data_import/sequencer.py @@ -1,4 +1,5 @@ -from typing import Any, Callable +from collections.abc import Callable +from typing import Any """ This module helps you set up a bunch diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py index 1a7eb2ec82..d88eecbd19 100644 --- a/zerver/data_import/slack.py +++ b/zerver/data_import/slack.py @@ -7,9 +7,10 @@ import secrets import shutil import zipfile from collections import defaultdict +from collections.abc import Iterator from datetime import datetime, timezone from email.headerregistry import Address -from typing import Any, Iterator, TypeVar +from typing import Any, TypeAlias, TypeVar from urllib.parse import urlsplit import orjson @@ -17,7 +18,6 @@ import requests from django.conf import settings from django.forms.models import model_to_dict from django.utils.timezone import now as timezone_now -from typing_extensions import TypeAlias from zerver.data_import.import_util import ( ZerverFieldsT, diff --git a/zerver/data_import/slack_message_conversion.py b/zerver/data_import/slack_message_conversion.py index 42edc417c9..d023e443b4 100644 --- a/zerver/data_import/slack_message_conversion.py +++ b/zerver/data_import/slack_message_conversion.py @@ -1,7 +1,5 @@ import re -from typing import Any - -from typing_extensions import TypeAlias +from typing import Any, TypeAlias # stubs ZerverFieldsT: TypeAlias = dict[str, Any] diff --git a/zerver/decorator.py b/zerver/decorator.py index ad574e66a5..4e7f987112 100644 --- a/zerver/decorator.py +++ b/zerver/decorator.py @@ -1,9 +1,10 @@ import base64 import logging +from collections.abc import Callable, Sequence from datetime import datetime from functools import wraps from io import BytesIO -from typing import TYPE_CHECKING, Callable, Sequence, TypeVar, cast, overload +from typing import TYPE_CHECKING, Concatenate, TypeVar, cast, overload from urllib.parse import urlsplit import django_otp @@ -23,7 +24,7 @@ from django.utils.translation import gettext as _ from django.views.decorators.csrf import csrf_exempt from django_otp import user_has_device from two_factor.utils import default_device -from typing_extensions import Concatenate, ParamSpec +from typing_extensions import ParamSpec from zerver.context_processors import get_valid_realm_from_request from zerver.lib.exceptions import ( diff --git a/zerver/lib/addressee.py b/zerver/lib/addressee.py index 700eb54a6a..e4ba5140ac 100644 --- a/zerver/lib/addressee.py +++ b/zerver/lib/addressee.py @@ -1,4 +1,5 @@ -from typing import Iterable, Sequence, cast +from collections.abc import Iterable, Sequence +from typing import cast from django.utils.translation import gettext as _ diff --git a/zerver/lib/alert_words.py b/zerver/lib/alert_words.py index aeedba2a4f..5e51928d54 100644 --- a/zerver/lib/alert_words.py +++ b/zerver/lib/alert_words.py @@ -1,4 +1,4 @@ -from typing import Iterable +from collections.abc import Iterable import ahocorasick from django.db import transaction diff --git a/zerver/lib/bot_lib.py b/zerver/lib/bot_lib.py index 68d3029171..fd28940102 100644 --- a/zerver/lib/bot_lib.py +++ b/zerver/lib/bot_lib.py @@ -1,6 +1,7 @@ import importlib import json -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from django.conf import settings from django.utils.translation import gettext as _ diff --git a/zerver/lib/bulk_create.py b/zerver/lib/bulk_create.py index 8ddc1991be..7bcd183b36 100644 --- a/zerver/lib/bulk_create.py +++ b/zerver/lib/bulk_create.py @@ -1,4 +1,5 @@ -from typing import Any, Collection, Iterable +from collections.abc import Collection, Iterable +from typing import Any from django.db.models import Model, QuerySet from django.utils.timezone import now as timezone_now diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 99861a433a..42da0c1f7f 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -7,8 +7,9 @@ import secrets import sys import time import traceback +from collections.abc import Callable, Iterable, Sequence from functools import _lru_cache_wrapper, lru_cache, wraps -from typing import TYPE_CHECKING, Any, Callable, Generic, Iterable, Sequence, TypeVar +from typing import TYPE_CHECKING, Any, Generic, TypeVar from django.conf import settings from django.core.cache import caches diff --git a/zerver/lib/cache_helpers.py b/zerver/lib/cache_helpers.py index 5e3788f6cb..2f729d250e 100644 --- a/zerver/lib/cache_helpers.py +++ b/zerver/lib/cache_helpers.py @@ -1,7 +1,8 @@ # See https://zulip.readthedocs.io/en/latest/subsystems/caching.html for docs import logging +from collections.abc import Callable, Iterable from datetime import timedelta -from typing import Any, Callable, Iterable +from typing import Any from django.conf import settings from django.contrib.sessions.models import Session diff --git a/zerver/lib/context_managers.py b/zerver/lib/context_managers.py index 31c55c74e4..cc159bc537 100644 --- a/zerver/lib/context_managers.py +++ b/zerver/lib/context_managers.py @@ -3,8 +3,9 @@ Context managers, i.e. things you can use with the 'with' statement. """ import fcntl +from collections.abc import Iterator from contextlib import contextmanager -from typing import IO, Any, Iterator +from typing import IO, Any @contextmanager diff --git a/zerver/lib/data_types.py b/zerver/lib/data_types.py index 7f9f8ea26b..ffdabe316b 100644 --- a/zerver/lib/data_types.py +++ b/zerver/lib/data_types.py @@ -9,9 +9,10 @@ the level of detail we desire or do comparison with OpenAPI types easily with the native Python type system. """ +from collections.abc import Callable, Sequence from contextlib import suppress from dataclasses import dataclass -from typing import Any, Callable, Sequence +from typing import Any from django.core.exceptions import ValidationError from django.core.validators import URLValidator diff --git a/zerver/lib/db.py b/zerver/lib/db.py index bfea3b4b61..813e2f314f 100644 --- a/zerver/lib/db.py +++ b/zerver/lib/db.py @@ -1,9 +1,10 @@ import time -from typing import Any, Callable, Iterable, Mapping, Sequence, TypeVar +from collections.abc import Callable, Iterable, Mapping, Sequence +from typing import Any, TypeAlias, TypeVar from psycopg2.extensions import connection, cursor from psycopg2.sql import Composable -from typing_extensions import TypeAlias, override +from typing_extensions import override CursorObj = TypeVar("CursorObj", bound=cursor) Query: TypeAlias = str | bytes | Composable diff --git a/zerver/lib/digest.py b/zerver/lib/digest.py index bf31dfa762..bc4e5c4e9a 100644 --- a/zerver/lib/digest.py +++ b/zerver/lib/digest.py @@ -2,15 +2,15 @@ import functools import heapq import logging from collections import defaultdict +from collections.abc import Collection, Iterator from datetime import datetime, timedelta, timezone -from typing import Any, Collection, Iterator +from typing import Any, TypeAlias from django.conf import settings from django.db import transaction 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 from confirmation.models import one_click_unsubscribe_link from zerver.context_processors import common_context diff --git a/zerver/lib/drafts.py b/zerver/lib/drafts.py index e97417c99a..65987b7574 100644 --- a/zerver/lib/drafts.py +++ b/zerver/lib/drafts.py @@ -1,12 +1,13 @@ import time +from collections.abc import Callable from functools import wraps -from typing import Any, Callable, Literal +from typing import Annotated, Any, Concatenate, Literal from django.core.exceptions import ValidationError from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ from pydantic import BaseModel, ConfigDict -from typing_extensions import Annotated, Concatenate, ParamSpec +from typing_extensions import ParamSpec from zerver.lib.addressee import get_user_profiles_by_ids from zerver.lib.exceptions import JsonableError, ResourceNotFoundError diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py index fd52ed7c72..61cdf2b512 100644 --- a/zerver/lib/email_mirror.py +++ b/zerver/lib/email_mirror.py @@ -3,7 +3,7 @@ import re import secrets from email.headerregistry import Address, AddressHeader from email.message import EmailMessage -from typing import Match +from re import Match from django.conf import settings from django.utils.translation import gettext as _ diff --git a/zerver/lib/email_mirror_helpers.py b/zerver/lib/email_mirror_helpers.py index 9ce0472192..c1b267cf32 100644 --- a/zerver/lib/email_mirror_helpers.py +++ b/zerver/lib/email_mirror_helpers.py @@ -1,5 +1,6 @@ import re -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from django.conf import settings from django.utils.text import slugify diff --git a/zerver/lib/email_validation.py b/zerver/lib/email_validation.py index 88ad339242..2b0f7f533c 100644 --- a/zerver/lib/email_validation.py +++ b/zerver/lib/email_validation.py @@ -1,6 +1,6 @@ +from collections.abc import Callable from email.errors import HeaderParseError from email.headerregistry import Address -from typing import Callable from django.core import validators from django.core.exceptions import ValidationError diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py index 328c51fe9c..9f5d4c8077 100644 --- a/zerver/lib/event_schema.py +++ b/zerver/lib/event_schema.py @@ -27,7 +27,7 @@ # See check_delete_message and check_presence for examples of this # paradigm. -from typing import Sequence +from collections.abc import Sequence from zerver.lib.data_types import ( DictType, diff --git a/zerver/lib/events.py b/zerver/lib/events.py index 5f837917f7..e7db80a8fc 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -3,7 +3,8 @@ import copy import logging import time -from typing import Any, Callable, Collection, Iterable, Mapping, Sequence +from collections.abc import Callable, Collection, Iterable, Mapping, Sequence +from typing import Any from django.conf import settings from django.utils.translation import gettext as _ diff --git a/zerver/lib/export.py b/zerver/lib/export.py index dd064e6125..a6e55a09b5 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -12,10 +12,11 @@ import os import shutil import subprocess import tempfile +from collections.abc import Callable, Iterable, Mapping from contextlib import suppress from datetime import datetime from functools import cache -from typing import Any, Callable, Iterable, Mapping, Optional, TypedDict +from typing import Any, Optional, TypeAlias, TypedDict import orjson from django.apps import apps @@ -24,7 +25,6 @@ from django.db.models import Exists, OuterRef, Q from django.forms.models import model_to_dict from django.utils.timezone import is_naive as timezone_is_naive from mypy_boto3_s3.service_resource import Object -from typing_extensions import TypeAlias import zerver.lib.upload from analytics.models import RealmCount, StreamCount, UserCount diff --git a/zerver/lib/fix_unreads.py b/zerver/lib/fix_unreads.py index 1d6b0a9681..99f28d7a4f 100644 --- a/zerver/lib/fix_unreads.py +++ b/zerver/lib/fix_unreads.py @@ -1,6 +1,7 @@ import logging import time -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from django.db import connection from django.db.backends.utils import CursorWrapper diff --git a/zerver/lib/html_to_text.py b/zerver/lib/html_to_text.py index af5cd6e456..fd8e661b9a 100644 --- a/zerver/lib/html_to_text.py +++ b/zerver/lib/html_to_text.py @@ -1,4 +1,4 @@ -from typing import Mapping +from collections.abc import Mapping from bs4 import BeautifulSoup from django.utils.html import escape diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index 6dbabae169..8e9fba5232 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -1,13 +1,13 @@ import os +from collections.abc import Callable, Sequence from dataclasses import dataclass, field -from typing import Any, Callable, Sequence +from typing import Any, TypeAlias from django.contrib.staticfiles.storage import staticfiles_storage from django.urls import URLResolver, path from django.utils.module_loading import import_string from django.utils.translation import gettext_lazy from django_stubs_ext import StrPromise -from typing_extensions import TypeAlias from zerver.lib.storage import static_path diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index 4708b629cb..f5897c2eb1 100644 --- a/zerver/lib/markdown/__init__.py +++ b/zerver/lib/markdown/__init__.py @@ -7,10 +7,12 @@ import mimetypes import re import time from collections import deque +from collections.abc import Callable from dataclasses import dataclass from datetime import datetime, timezone from functools import lru_cache -from typing import Any, Callable, Generic, Match, Optional, Pattern, TypedDict, TypeVar, cast +from re import Match, Pattern +from typing import Any, Generic, Optional, TypeAlias, TypedDict, TypeVar, cast from urllib.parse import parse_qs, quote, urlencode, urljoin, urlsplit, urlunsplit from xml.etree.ElementTree import Element, SubElement @@ -34,7 +36,7 @@ from django.conf import settings from markdown.blockparser import BlockParser from markdown.extensions import codehilite, nl2br, sane_lists, tables from tlds import tld_set -from typing_extensions import Self, TypeAlias, override +from typing_extensions import Self, override from zerver.lib import mention from zerver.lib.cache import cache_with_key diff --git a/zerver/lib/markdown/api_arguments_table_generator.py b/zerver/lib/markdown/api_arguments_table_generator.py index 5ec984006a..324cc27f83 100644 --- a/zerver/lib/markdown/api_arguments_table_generator.py +++ b/zerver/lib/markdown/api_arguments_table_generator.py @@ -1,6 +1,7 @@ import json import re -from typing import Any, Mapping, Sequence +from collections.abc import Mapping, Sequence +from typing import Any import markdown from django.utils.html import escape as escape_html diff --git a/zerver/lib/markdown/api_return_values_table_generator.py b/zerver/lib/markdown/api_return_values_table_generator.py index 2d792c61ca..ff8958e0aa 100644 --- a/zerver/lib/markdown/api_return_values_table_generator.py +++ b/zerver/lib/markdown/api_return_values_table_generator.py @@ -2,8 +2,9 @@ import copy import json import re from collections import OrderedDict +from collections.abc import Mapping from dataclasses import dataclass -from typing import Any, Mapping +from typing import Any import markdown from markdown.extensions import Extension diff --git a/zerver/lib/markdown/fenced_code.py b/zerver/lib/markdown/fenced_code.py index c82200f327..ba6fc55e1a 100644 --- a/zerver/lib/markdown/fenced_code.py +++ b/zerver/lib/markdown/fenced_code.py @@ -77,7 +77,8 @@ Dependencies: """ import re -from typing import Any, Callable, Iterable, Mapping, MutableSequence, Sequence +from collections.abc import Callable, Iterable, Mapping, MutableSequence, Sequence +from typing import Any import lxml.html from django.utils.html import escape diff --git a/zerver/lib/markdown/help_emoticon_translations_table.py b/zerver/lib/markdown/help_emoticon_translations_table.py index 283ab1217a..def19a066a 100644 --- a/zerver/lib/markdown/help_emoticon_translations_table.py +++ b/zerver/lib/markdown/help_emoticon_translations_table.py @@ -1,5 +1,6 @@ import re -from typing import Any, Match +from re import Match +from typing import Any from markdown import Markdown from markdown.extensions import Extension diff --git a/zerver/lib/markdown/help_relative_links.py b/zerver/lib/markdown/help_relative_links.py index 87b6842ea6..baaf7b7a8b 100644 --- a/zerver/lib/markdown/help_relative_links.py +++ b/zerver/lib/markdown/help_relative_links.py @@ -1,5 +1,6 @@ import re -from typing import Any, Match +from re import Match +from typing import Any from markdown import Markdown from markdown.extensions import Extension diff --git a/zerver/lib/markdown/help_settings_links.py b/zerver/lib/markdown/help_settings_links.py index 7bc1bc3003..0ac75c9d49 100644 --- a/zerver/lib/markdown/help_settings_links.py +++ b/zerver/lib/markdown/help_settings_links.py @@ -1,5 +1,6 @@ import re -from typing import Any, Match +from re import Match +from typing import Any from markdown import Markdown from markdown.extensions import Extension diff --git a/zerver/lib/markdown/include.py b/zerver/lib/markdown/include.py index 4f5a05ce1f..b3aa5c27bb 100644 --- a/zerver/lib/markdown/include.py +++ b/zerver/lib/markdown/include.py @@ -1,6 +1,6 @@ import os import re -from typing import Match +from re import Match from xml.etree.ElementTree import Element from markdown import Extension, Markdown diff --git a/zerver/lib/markdown/nested_code_blocks.py b/zerver/lib/markdown/nested_code_blocks.py index 69c9718392..d0e1cfa827 100644 --- a/zerver/lib/markdown/nested_code_blocks.py +++ b/zerver/lib/markdown/nested_code_blocks.py @@ -1,4 +1,5 @@ -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from xml.etree.ElementTree import Element, SubElement import markdown diff --git a/zerver/lib/markdown/tabbed_sections.py b/zerver/lib/markdown/tabbed_sections.py index 706379a8da..9a1bfb9225 100644 --- a/zerver/lib/markdown/tabbed_sections.py +++ b/zerver/lib/markdown/tabbed_sections.py @@ -1,5 +1,6 @@ import re -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any import markdown from markdown.extensions import Extension diff --git a/zerver/lib/mention.py b/zerver/lib/mention.py index a55593456c..bc7c535d4f 100644 --- a/zerver/lib/mention.py +++ b/zerver/lib/mention.py @@ -1,7 +1,7 @@ import functools import re from dataclasses import dataclass -from typing import Match +from re import Match from django.conf import settings from django.db.models import Q diff --git a/zerver/lib/message.py b/zerver/lib/message.py index b5457fd65d..39f85045ae 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -1,7 +1,8 @@ import re +from collections.abc import Callable, Collection, Mapping, Sequence from dataclasses import dataclass, field from datetime import datetime, timedelta -from typing import Any, Callable, Collection, Mapping, Sequence, TypedDict +from typing import Any, TypedDict from django.conf import settings from django.db import connection diff --git a/zerver/lib/message_cache.py b/zerver/lib/message_cache.py index 9e7ec70932..c032534e8a 100644 --- a/zerver/lib/message_cache.py +++ b/zerver/lib/message_cache.py @@ -1,8 +1,9 @@ import copy import zlib +from collections.abc import Iterable from datetime import datetime from email.headerregistry import Address -from typing import Any, Iterable, TypedDict +from typing import Any, TypedDict import orjson diff --git a/zerver/lib/migrate.py b/zerver/lib/migrate.py index f78df11c64..cb5c37e6f8 100644 --- a/zerver/lib/migrate.py +++ b/zerver/lib/migrate.py @@ -1,5 +1,6 @@ import time -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from django.db import connection from django.db.backends.base.schema import BaseDatabaseSchemaEditor diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.py index 7643fbcdbd..526cd6408a 100644 --- a/zerver/lib/narrow.py +++ b/zerver/lib/narrow.py @@ -1,6 +1,7 @@ import re +from collections.abc import Callable, Iterable, Sequence from dataclasses import dataclass -from typing import Any, Callable, Generic, Iterable, Sequence, TypeVar +from typing import Any, Generic, TypeAlias, TypeVar from django.conf import settings from django.contrib.auth.models import AnonymousUser @@ -29,7 +30,7 @@ from sqlalchemy.sql import ( ) from sqlalchemy.sql.selectable import SelectBase from sqlalchemy.types import ARRAY, Boolean, Integer, Text -from typing_extensions import TypeAlias, override +from typing_extensions import override from zerver.lib.addressee import get_user_profiles, get_user_profiles_by_ids from zerver.lib.exceptions import ErrorCode, JsonableError, MissingAuthenticationError diff --git a/zerver/lib/narrow_helpers.py b/zerver/lib/narrow_helpers.py index 49e1d2fb9e..296ac17d6c 100644 --- a/zerver/lib/narrow_helpers.py +++ b/zerver/lib/narrow_helpers.py @@ -19,8 +19,8 @@ from users: """ import os +from collections.abc import Collection, Sequence from dataclasses import dataclass -from typing import Collection, Sequence from django.conf import settings diff --git a/zerver/lib/narrow_predicate.py b/zerver/lib/narrow_predicate.py index f76241e00b..954f578916 100644 --- a/zerver/lib/narrow_predicate.py +++ b/zerver/lib/narrow_predicate.py @@ -1,4 +1,5 @@ -from typing import Any, Collection, Protocol +from collections.abc import Collection +from typing import Any, Protocol from django.utils.translation import gettext as _ diff --git a/zerver/lib/notes.py b/zerver/lib/notes.py index 5ba9d2f226..92a7f953c2 100644 --- a/zerver/lib/notes.py +++ b/zerver/lib/notes.py @@ -1,6 +1,7 @@ import weakref from abc import ABCMeta, abstractmethod -from typing import Any, ClassVar, Generic, MutableMapping, TypeVar +from collections.abc import MutableMapping +from typing import Any, ClassVar, Generic, TypeVar from typing_extensions import override diff --git a/zerver/lib/notification_data.py b/zerver/lib/notification_data.py index d35df0be4f..8ae5be7537 100644 --- a/zerver/lib/notification_data.py +++ b/zerver/lib/notification_data.py @@ -1,6 +1,7 @@ import math +from collections.abc import Collection from dataclasses import dataclass -from typing import Any, Collection +from typing import Any from zerver.lib.mention import MentionData from zerver.lib.user_groups import get_user_group_member_ids diff --git a/zerver/lib/partial.py b/zerver/lib/partial.py index 0a20fbebd5..fd409b56b8 100644 --- a/zerver/lib/partial.py +++ b/zerver/lib/partial.py @@ -1,10 +1,13 @@ # Workaround for missing functools.partial support in mypy # (https://github.com/python/mypy/issues/1484). -from typing import TYPE_CHECKING, Callable, TypeVar, overload +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar, overload if TYPE_CHECKING: - from typing_extensions import Concatenate, ParamSpec + from typing import Concatenate + + from typing_extensions import ParamSpec P = ParamSpec("P") T1 = TypeVar("T1") diff --git a/zerver/lib/per_request_cache.py b/zerver/lib/per_request_cache.py index 7750079bb0..9a759ad400 100644 --- a/zerver/lib/per_request_cache.py +++ b/zerver/lib/per_request_cache.py @@ -1,4 +1,5 @@ -from typing import Any, Callable, TypeVar +from collections.abc import Callable +from typing import Any, TypeVar ReturnT = TypeVar("ReturnT") diff --git a/zerver/lib/presence.py b/zerver/lib/presence.py index 426328359b..ac6dc5bfec 100644 --- a/zerver/lib/presence.py +++ b/zerver/lib/presence.py @@ -1,7 +1,8 @@ import time from collections import defaultdict +from collections.abc import Mapping, Sequence from datetime import datetime, timedelta -from typing import Any, Mapping, Sequence +from typing import Any from django.conf import settings from django.utils.timezone import now as timezone_now diff --git a/zerver/lib/profile.py b/zerver/lib/profile.py index 09488a5336..58ccefcbcf 100644 --- a/zerver/lib/profile.py +++ b/zerver/lib/profile.py @@ -1,6 +1,7 @@ import cProfile +from collections.abc import Callable from functools import wraps -from typing import Callable, TypeVar +from typing import TypeVar from typing_extensions import ParamSpec diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index 55fb1b632d..de8375686d 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -5,10 +5,11 @@ import base64 import copy import logging import re +from collections.abc import Iterable, Mapping, Sequence from dataclasses import dataclass from email.headerregistry import Address from functools import cache -from typing import TYPE_CHECKING, Any, Iterable, Mapping, Optional, Sequence, Union +from typing import TYPE_CHECKING, Any, Optional, TypeAlias, Union import lxml.html import orjson @@ -24,7 +25,7 @@ from firebase_admin import exceptions as firebase_exceptions from firebase_admin import initialize_app as firebase_initialize_app from firebase_admin import messaging as firebase_messaging from firebase_admin.messaging import UnregisteredError as FCMUnregisteredError -from typing_extensions import TypeAlias, override +from typing_extensions import override from analytics.lib.counts import COUNT_STATS, do_increment_logging_stat from zerver.actions.realm_settings import ( diff --git a/zerver/lib/queue.py b/zerver/lib/queue.py index ea12801485..5f8063783c 100644 --- a/zerver/lib/queue.py +++ b/zerver/lib/queue.py @@ -5,7 +5,8 @@ import threading import time from abc import ABCMeta, abstractmethod from collections import defaultdict -from typing import Any, Callable, Generic, Mapping, TypeVar +from collections.abc import Callable, Mapping +from typing import Any, Generic, TypeAlias, TypeVar import orjson import pika @@ -18,7 +19,7 @@ from pika.adapters.blocking_connection import BlockingChannel from pika.channel import Channel from pika.spec import Basic from tornado import ioloop -from typing_extensions import TypeAlias, override +from typing_extensions import override from zerver.lib.utils import assert_is_not_none diff --git a/zerver/lib/recipient_users.py b/zerver/lib/recipient_users.py index b0e03e6d77..f6a94fcdfe 100644 --- a/zerver/lib/recipient_users.py +++ b/zerver/lib/recipient_users.py @@ -1,4 +1,4 @@ -from typing import Sequence +from collections.abc import Sequence from django.core.exceptions import ValidationError from django.utils.translation import gettext as _ diff --git a/zerver/lib/redis_utils.py b/zerver/lib/redis_utils.py index 89f818ddf0..0a4636a28f 100644 --- a/zerver/lib/redis_utils.py +++ b/zerver/lib/redis_utils.py @@ -1,7 +1,8 @@ import os import re import secrets -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any import orjson import redis diff --git a/zerver/lib/remote_server.py b/zerver/lib/remote_server.py index 75b6dd5677..e231a171ae 100644 --- a/zerver/lib/remote_server.py +++ b/zerver/lib/remote_server.py @@ -1,5 +1,6 @@ import logging -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from urllib.parse import urljoin import orjson diff --git a/zerver/lib/request.py b/zerver/lib/request.py index bcf6b41871..b1d79fd1b7 100644 --- a/zerver/lib/request.py +++ b/zerver/lib/request.py @@ -1,26 +1,16 @@ from collections import defaultdict +from collections.abc import Callable, MutableMapping, Sequence from dataclasses import dataclass, field from functools import wraps from types import FunctionType -from typing import ( - Any, - Callable, - Generic, - Literal, - MutableMapping, - Optional, - Sequence, - TypeVar, - cast, - overload, -) +from typing import Any, Concatenate, Generic, Literal, Optional, TypeVar, cast, overload import orjson from django.conf import settings from django.core.exceptions import ValidationError from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ -from typing_extensions import Concatenate, ParamSpec, override +from typing_extensions import ParamSpec, override from zerver.lib import rate_limiter from zerver.lib.exceptions import ErrorCode, InvalidJSONError, JsonableError diff --git a/zerver/lib/response.py b/zerver/lib/response.py index 44ebf7555d..8fb54dee30 100644 --- a/zerver/lib/response.py +++ b/zerver/lib/response.py @@ -1,4 +1,5 @@ -from typing import Any, Iterator, Mapping +from collections.abc import Iterator, Mapping +from typing import Any import orjson from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed diff --git a/zerver/lib/rest.py b/zerver/lib/rest.py index 309bf6e86d..acd0bfb98d 100644 --- a/zerver/lib/rest.py +++ b/zerver/lib/rest.py @@ -1,12 +1,13 @@ +from collections.abc import Callable from functools import wraps -from typing import Callable +from typing import Concatenate from django.http import HttpRequest, HttpResponse, HttpResponseBase from django.urls import path from django.urls.resolvers import URLPattern from django.utils.cache import add_never_cache_headers from django.views.decorators.csrf import csrf_exempt, csrf_protect -from typing_extensions import Concatenate, ParamSpec +from typing_extensions import ParamSpec from zerver.decorator import ( authenticated_json_view, diff --git a/zerver/lib/retention.py b/zerver/lib/retention.py index 17f588eac9..eac16d969e 100644 --- a/zerver/lib/retention.py +++ b/zerver/lib/retention.py @@ -28,8 +28,9 @@ # deletions. import logging import time +from collections.abc import Iterable, Mapping from datetime import timedelta -from typing import Any, Iterable, Mapping +from typing import Any from django.conf import settings from django.db import connection, transaction diff --git a/zerver/lib/scim.py b/zerver/lib/scim.py index 24a24a4313..c4387d5c55 100644 --- a/zerver/lib/scim.py +++ b/zerver/lib/scim.py @@ -1,4 +1,5 @@ -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import django_scim.constants as scim_constants import django_scim.exceptions as scim_exceptions diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.py index 8578dd0c49..5ee054b1ab 100644 --- a/zerver/lib/send_email.py +++ b/zerver/lib/send_email.py @@ -2,13 +2,14 @@ import hashlib import logging import os import smtplib +from collections.abc import Callable, Mapping from contextlib import suppress from datetime import timedelta from email.headerregistry import Address from email.parser import Parser from email.policy import default from email.utils import formataddr, parseaddr -from typing import Any, Callable, Mapping +from typing import Any import backoff import css_inline diff --git a/zerver/lib/server_initialization.py b/zerver/lib/server_initialization.py index a4af76378e..353f59997f 100644 --- a/zerver/lib/server_initialization.py +++ b/zerver/lib/server_initialization.py @@ -1,4 +1,4 @@ -from typing import Iterable +from collections.abc import Iterable from django.conf import settings from django.db import transaction diff --git a/zerver/lib/sessions.py b/zerver/lib/sessions.py index 239eec5af8..196afbf48e 100644 --- a/zerver/lib/sessions.py +++ b/zerver/lib/sessions.py @@ -1,7 +1,8 @@ import logging +from collections.abc import Mapping from datetime import timedelta from importlib import import_module -from typing import Any, Mapping, Protocol, cast +from typing import Any, Protocol, cast from django.conf import settings from django.contrib.auth import SESSION_KEY, get_user_model diff --git a/zerver/lib/soft_deactivation.py b/zerver/lib/soft_deactivation.py index 8f2b8df851..b4739a4433 100644 --- a/zerver/lib/soft_deactivation.py +++ b/zerver/lib/soft_deactivation.py @@ -1,7 +1,8 @@ # Documented in https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html#soft-deactivation import logging from collections import defaultdict -from typing import Any, Iterable, Sequence, TypedDict +from collections.abc import Iterable, Sequence +from typing import Any, TypedDict from django.conf import settings from django.db import transaction diff --git a/zerver/lib/sqlalchemy_utils.py b/zerver/lib/sqlalchemy_utils.py index dcc8e9c039..ace89e353c 100644 --- a/zerver/lib/sqlalchemy_utils.py +++ b/zerver/lib/sqlalchemy_utils.py @@ -1,5 +1,5 @@ +from collections.abc import Iterator from contextlib import contextmanager -from typing import Iterator import sqlalchemy from django.db import connection diff --git a/zerver/lib/stream_subscription.py b/zerver/lib/stream_subscription.py index af3a011a66..719114c9b4 100644 --- a/zerver/lib/stream_subscription.py +++ b/zerver/lib/stream_subscription.py @@ -1,8 +1,10 @@ import itertools from collections import defaultdict +from collections.abc import Collection +from collections.abc import Set as AbstractSet from dataclasses import dataclass from operator import itemgetter -from typing import AbstractSet, Any, Collection +from typing import Any from django.db.models import Q, QuerySet from django_stubs_ext import ValuesQuerySet diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index d9887b96b6..a9953c628c 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -1,4 +1,5 @@ -from typing import Collection, TypedDict +from collections.abc import Collection +from typing import TypedDict from django.db import transaction from django.db.models import Exists, OuterRef, Q, QuerySet diff --git a/zerver/lib/subscription_info.py b/zerver/lib/subscription_info.py index 22a77e36a3..a6b13de712 100644 --- a/zerver/lib/subscription_info.py +++ b/zerver/lib/subscription_info.py @@ -1,6 +1,7 @@ import itertools +from collections.abc import Callable, Collection, Iterable, Mapping from operator import itemgetter -from typing import Any, Callable, Collection, Iterable, Mapping +from typing import Any from django.core.exceptions import ValidationError from django.db import connection diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index 72ad307b38..fc456d32c9 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -4,19 +4,10 @@ import re import shutil import subprocess import tempfile +from collections.abc import Callable, Collection, Iterator, Mapping, Sequence from contextlib import contextmanager from datetime import timedelta -from typing import ( - TYPE_CHECKING, - Any, - Callable, - Collection, - Iterator, - Mapping, - Sequence, - Union, - cast, -) +from typing import TYPE_CHECKING, Any, Union, cast from unittest import TestResult, mock, skipUnless from urllib.parse import parse_qs, quote, urlencode diff --git a/zerver/lib/test_console_output.py b/zerver/lib/test_console_output.py index 13089a8759..17a5cc328c 100644 --- a/zerver/lib/test_console_output.py +++ b/zerver/lib/test_console_output.py @@ -2,10 +2,11 @@ import itertools import logging import re import sys +from collections.abc import Iterable, Iterator from contextlib import contextmanager from io import SEEK_SET, TextIOWrapper from types import TracebackType -from typing import IO, TYPE_CHECKING, Iterable, Iterator +from typing import IO, TYPE_CHECKING from typing_extensions import override diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py index 6c6bf37d07..1824f6ff55 100644 --- a/zerver/lib/test_helpers.py +++ b/zerver/lib/test_helpers.py @@ -4,20 +4,10 @@ import os import re import sys import time +from collections.abc import Callable, Iterable, Iterator, Mapping from contextlib import contextmanager from dataclasses import dataclass -from typing import ( - IO, - TYPE_CHECKING, - Any, - Callable, - Iterable, - Iterator, - Mapping, - TypeVar, - Union, - cast, -) +from typing import IO, TYPE_CHECKING, Any, TypeVar, Union, cast from unittest import mock from unittest.mock import patch diff --git a/zerver/lib/test_runner.py b/zerver/lib/test_runner.py index 5dcdb472b9..c5823acdc6 100644 --- a/zerver/lib/test_runner.py +++ b/zerver/lib/test_runner.py @@ -3,7 +3,8 @@ import os import random import shutil import unittest -from typing import Any, Callable, Iterable +from collections.abc import Callable, Iterable +from typing import Any, TypeAlias from unittest import TestSuite, runner from unittest.result import TestResult @@ -13,7 +14,7 @@ from django.db import ProgrammingError, connections from django.test import runner as django_runner from django.test.runner import DiscoverRunner from django.test.signals import template_rendered -from typing_extensions import TypeAlias, override +from typing_extensions import override from scripts.lib.zulip_tools import ( TEMPLATE_DATABASE_DIR, diff --git a/zerver/lib/thumbnail.py b/zerver/lib/thumbnail.py index c5fefd3563..b61daf69e3 100644 --- a/zerver/lib/thumbnail.py +++ b/zerver/lib/thumbnail.py @@ -1,7 +1,7 @@ import logging import os +from collections.abc import Iterator from contextlib import contextmanager -from typing import Iterator from urllib.parse import urljoin import pyvips diff --git a/zerver/lib/timeout.py b/zerver/lib/timeout.py index 395e95fb05..fb07ee2f6b 100644 --- a/zerver/lib/timeout.py +++ b/zerver/lib/timeout.py @@ -3,8 +3,9 @@ import logging import sys import threading import time +from collections.abc import Callable from types import TracebackType -from typing import Callable, TypeVar +from typing import TypeVar from typing_extensions import override diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py index 8e755728a6..7737c26ae1 100644 --- a/zerver/lib/topic.py +++ b/zerver/lib/topic.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from datetime import datetime -from typing import Any, Callable +from typing import Any import orjson from django.db import connection diff --git a/zerver/lib/typed_endpoint.py b/zerver/lib/typed_endpoint.py index 70c1024987..02a77ac3e8 100644 --- a/zerver/lib/typed_endpoint.py +++ b/zerver/lib/typed_endpoint.py @@ -1,24 +1,27 @@ import inspect import json import types +from collections.abc import Callable, Sequence from dataclasses import dataclass from enum import Enum, auto from functools import wraps -from typing import Callable, Generic, Sequence, TypeVar, Union - -from django.http import HttpRequest -from django.utils.translation import gettext as _ -from pydantic import Json, StringConstraints, TypeAdapter, ValidationError -from typing_extensions import ( +from typing import ( Annotated, Concatenate, - ParamSpec, + Generic, TypeAlias, + TypeVar, + Union, get_args, get_origin, get_type_hints, ) +from django.http import HttpRequest +from django.utils.translation import gettext as _ +from pydantic import Json, StringConstraints, TypeAdapter, ValidationError +from typing_extensions import ParamSpec + from zerver.lib.exceptions import ApiParamValidationError, JsonableError from zerver.lib.request import ( _REQ, diff --git a/zerver/lib/types.py b/zerver/lib/types.py index d33a6b05aa..eda4ab3c19 100644 --- a/zerver/lib/types.py +++ b/zerver/lib/types.py @@ -1,9 +1,10 @@ +from collections.abc import Callable from dataclasses import dataclass, field from datetime import datetime -from typing import Any, Callable, TypeVar +from typing import Any, TypeAlias, TypeVar from django_stubs_ext import StrPromise -from typing_extensions import NotRequired, TypeAlias, TypedDict +from typing_extensions import NotRequired, TypedDict # See zerver/lib/validator.py for more details of Validators, # including many examples diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py index a3659c0ea5..ad50766f15 100644 --- a/zerver/lib/upload/__init__.py +++ b/zerver/lib/upload/__init__.py @@ -3,8 +3,9 @@ import logging import os import re import unicodedata +from collections.abc import Callable, Iterator from datetime import datetime -from typing import IO, Any, BinaryIO, Callable, Iterator +from typing import IO, Any, BinaryIO from urllib.parse import unquote, urljoin from django.conf import settings diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.py index bf0a0cb5fb..a04733abfc 100644 --- a/zerver/lib/upload/base.py +++ b/zerver/lib/upload/base.py @@ -1,6 +1,7 @@ import os +from collections.abc import Callable, Iterator from datetime import datetime -from typing import IO, Any, BinaryIO, Callable, Iterator +from typing import IO, Any, BinaryIO from zerver.models import Realm, UserProfile diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.py index 2e705c8745..4deed9668d 100644 --- a/zerver/lib/upload/local.py +++ b/zerver/lib/upload/local.py @@ -3,8 +3,9 @@ import os import random import secrets import shutil +from collections.abc import Callable, Iterator from datetime import datetime -from typing import IO, Any, BinaryIO, Callable, Iterator, Literal +from typing import IO, Any, BinaryIO, Literal from django.conf import settings from typing_extensions import override diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.py index 66e2d3d21d..eae899f2f7 100644 --- a/zerver/lib/upload/s3.py +++ b/zerver/lib/upload/s3.py @@ -1,8 +1,9 @@ import logging import os import secrets +from collections.abc import Callable, Iterator from datetime import datetime -from typing import IO, Any, BinaryIO, Callable, Iterator, Literal +from typing import IO, Any, BinaryIO, Literal from urllib.parse import urljoin, urlsplit, urlunsplit import boto3 diff --git a/zerver/lib/url_preview/preview.py b/zerver/lib/url_preview/preview.py index 8781cce7cb..d790f957b6 100644 --- a/zerver/lib/url_preview/preview.py +++ b/zerver/lib/url_preview/preview.py @@ -1,5 +1,7 @@ import re -from typing import Any, Callable, Match +from collections.abc import Callable +from re import Match +from typing import Any from urllib.parse import urljoin import magic diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.py index 130768a89d..fbf4613362 100644 --- a/zerver/lib/user_groups.py +++ b/zerver/lib/user_groups.py @@ -1,6 +1,7 @@ +from collections.abc import Collection, Iterable, Iterator, Mapping from contextlib import contextmanager from dataclasses import asdict, dataclass -from typing import Collection, Iterable, Iterator, Mapping, TypedDict +from typing import TypedDict from django.conf import settings from django.db import connection, transaction diff --git a/zerver/lib/user_topics.py b/zerver/lib/user_topics.py index b688b8764c..661c5f03bd 100644 --- a/zerver/lib/user_topics.py +++ b/zerver/lib/user_topics.py @@ -1,7 +1,8 @@ import logging from collections import defaultdict +from collections.abc import Callable from datetime import datetime -from typing import Callable, TypedDict +from typing import TypedDict from django.db import connection, transaction from django.db.models import QuerySet diff --git a/zerver/lib/users.py b/zerver/lib/users.py index 9197bd1d7d..2accb3da74 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -2,9 +2,10 @@ import itertools import re import unicodedata from collections import defaultdict +from collections.abc import Iterable, Mapping, Sequence from email.headerregistry import Address from operator import itemgetter -from typing import Any, Iterable, Mapping, Sequence, TypedDict +from typing import Any, TypedDict import dateutil.parser as date_parser from django.conf import settings diff --git a/zerver/lib/utils.py b/zerver/lib/utils.py index 7346588fc9..ea16c7d0e0 100644 --- a/zerver/lib/utils.py +++ b/zerver/lib/utils.py @@ -1,6 +1,7 @@ import re import secrets -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar T = TypeVar("T") diff --git a/zerver/lib/validator.py b/zerver/lib/validator.py index e40b217dd1..948218bce9 100644 --- a/zerver/lib/validator.py +++ b/zerver/lib/validator.py @@ -29,9 +29,10 @@ for any particular type of object. """ import re +from collections.abc import Callable, Collection, Container, Iterator from dataclasses import dataclass from datetime import datetime, timezone -from typing import Any, Callable, Collection, Container, Iterator, NoReturn, TypeVar, cast, overload +from typing import Any, NoReturn, TypeVar, cast, overload import orjson import zoneinfo diff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.py index 366644824c..a95884468a 100644 --- a/zerver/lib/webhooks/common.py +++ b/zerver/lib/webhooks/common.py @@ -1,13 +1,14 @@ import fnmatch import importlib +from collections.abc import Callable from datetime import datetime -from typing import Any, Callable +from typing import Annotated, Any, TypeAlias from urllib.parse import unquote from django.http import HttpRequest from django.utils.translation import gettext as _ from pydantic import Json -from typing_extensions import Annotated, TypeAlias, override +from typing_extensions import override from zerver.actions.message_send import ( check_send_private_message, diff --git a/zerver/management/commands/check_redis.py b/zerver/management/commands/check_redis.py index 1a8bacb96c..438e12c817 100644 --- a/zerver/management/commands/check_redis.py +++ b/zerver/management/commands/check_redis.py @@ -1,6 +1,7 @@ import logging import time -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from django.conf import settings from django.core.management.base import CommandError, CommandParser diff --git a/zerver/management/commands/email_mirror.py b/zerver/management/commands/email_mirror.py index 70ba182db8..6f5faa298b 100644 --- a/zerver/management/commands/email_mirror.py +++ b/zerver/management/commands/email_mirror.py @@ -21,9 +21,10 @@ recipient address and retrieve, forward, and archive the message. import email import email.policy import logging +from collections.abc import Generator from email.message import EmailMessage from imaplib import IMAP4_SSL -from typing import Any, Generator +from typing import Any from django.conf import settings from django.core.management.base import CommandError diff --git a/zerver/management/commands/makemessages.py b/zerver/management/commands/makemessages.py index 2fa814a407..397f286ac1 100644 --- a/zerver/management/commands/makemessages.py +++ b/zerver/management/commands/makemessages.py @@ -38,7 +38,8 @@ import json import os import re import subprocess -from typing import Any, Collection, Iterator, Mapping +from collections.abc import Collection, Iterator, Mapping +from typing import Any from django.core.management.base import CommandParser from django.core.management.commands import makemessages diff --git a/zerver/management/commands/process_queue.py b/zerver/management/commands/process_queue.py index 550bb98cee..f5439116b3 100644 --- a/zerver/management/commands/process_queue.py +++ b/zerver/management/commands/process_queue.py @@ -4,9 +4,10 @@ import signal import sys import threading from argparse import ArgumentParser +from collections.abc import Iterator from contextlib import contextmanager from types import FrameType -from typing import Any, Iterator +from typing import Any from django.conf import settings from django.core.management.base import CommandError diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.py index 5996fe89da..ed6ed91dc3 100644 --- a/zerver/management/commands/send_custom_email.py +++ b/zerver/management/commands/send_custom_email.py @@ -1,5 +1,6 @@ from argparse import ArgumentParser -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import orjson from django.conf import settings diff --git a/zerver/middleware.py b/zerver/middleware.py index e63f9c3a88..ab94d12801 100644 --- a/zerver/middleware.py +++ b/zerver/middleware.py @@ -2,7 +2,8 @@ import cProfile import logging import tempfile import time -from typing import Any, Callable, MutableMapping +from collections.abc import Callable, MutableMapping +from typing import Annotated, Any, Concatenate from urllib.parse import urlencode, urljoin from django.conf import settings @@ -22,7 +23,7 @@ from django.utils.translation import gettext as _ from django_scim.middleware import SCIMAuthCheckMiddleware from django_scim.settings import scim_settings from sentry_sdk import set_tag -from typing_extensions import Annotated, Concatenate, ParamSpec, override +from typing_extensions import ParamSpec, override from zerver.lib.cache import get_remote_cache_requests, get_remote_cache_time from zerver.lib.db_connections import reset_queries diff --git a/zerver/migrations/0553_copy_emoji_images.py b/zerver/migrations/0553_copy_emoji_images.py index de5f2f3af6..ccfa296dc3 100644 --- a/zerver/migrations/0553_copy_emoji_images.py +++ b/zerver/migrations/0553_copy_emoji_images.py @@ -2,7 +2,8 @@ import contextlib import hashlib import logging import os -from typing import Any, Iterator +from collections.abc import Iterator +from typing import Any import boto3 import botocore diff --git a/zerver/models/custom_profile_fields.py b/zerver/models/custom_profile_fields.py index 7cc3339b81..5c39ada3ff 100644 --- a/zerver/models/custom_profile_fields.py +++ b/zerver/models/custom_profile_fields.py @@ -1,4 +1,5 @@ -from typing import Any, Callable +from collections.abc import Callable +from typing import Any import orjson from django.core.exceptions import ValidationError diff --git a/zerver/models/linkifiers.py b/zerver/models/linkifiers.py index 3f10d816d6..db3a69273a 100644 --- a/zerver/models/linkifiers.py +++ b/zerver/models/linkifiers.py @@ -1,4 +1,4 @@ -from typing import Pattern +from re import Pattern import re2 import uri_template diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.py index da23d6074f..7a7def93b2 100644 --- a/zerver/openapi/curl_param_value_generators.py +++ b/zerver/openapi/curl_param_value_generators.py @@ -5,8 +5,9 @@ # based on Zulip's OpenAPI definitions, as well as test setup and # fetching of appropriate parameter values to use when running the # cURL examples as part of the tools/test-api test suite. +from collections.abc import Callable from functools import wraps -from typing import Any, Callable +from typing import Any from django.utils.timezone import now as timezone_now diff --git a/zerver/openapi/markdown_extension.py b/zerver/openapi/markdown_extension.py index 1fc5abd011..fcf8f14065 100644 --- a/zerver/openapi/markdown_extension.py +++ b/zerver/openapi/markdown_extension.py @@ -9,8 +9,10 @@ import inspect import json import re import shlex +from collections.abc import Mapping +from re import Match, Pattern from textwrap import dedent -from typing import Any, Mapping, Match, Pattern +from typing import Any import markdown from django.conf import settings diff --git a/zerver/openapi/openapi.py b/zerver/openapi/openapi.py index d2c23216e3..b7a7a48745 100644 --- a/zerver/openapi/openapi.py +++ b/zerver/openapi/openapi.py @@ -8,7 +8,8 @@ import json import os import re -from typing import Any, Literal, Mapping +from collections.abc import Mapping +from typing import Any, Literal import orjson from openapi_core import OpenAPI diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.py index 6fb9a5f0ab..ce5dc489fc 100644 --- a/zerver/openapi/python_examples.py +++ b/zerver/openapi/python_examples.py @@ -15,9 +15,10 @@ import json import os import sys +from collections.abc import Callable from email.headerregistry import Address from functools import wraps -from typing import Any, Callable, TypeVar +from typing import Any, TypeVar from typing_extensions import ParamSpec from zulip import Client diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index 50715016fe..3e355cf9f4 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -6,10 +6,11 @@ import re import secrets import time from abc import ABC, abstractmethod +from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from contextlib import contextmanager from datetime import timedelta from email.headerregistry import Address -from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator, Mapping, Sequence +from typing import TYPE_CHECKING, Any from unittest import mock from urllib.parse import parse_qs, urlencode, urlsplit diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py index 776e3e94b7..6fc774e89c 100644 --- a/zerver/tests/test_custom_profile_data.py +++ b/zerver/tests/test_custom_profile_data.py @@ -1,4 +1,5 @@ -from typing import Any, Iterable, cast +from collections.abc import Iterable +from typing import Any, cast from unittest import mock import orjson diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index 5e536129db..b1098d38c7 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -3,7 +3,8 @@ import os import re import uuid from collections import defaultdict -from typing import TYPE_CHECKING, Any, Callable +from collections.abc import Callable +from typing import TYPE_CHECKING, Any from unittest import mock, skipUnless import orjson diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index bb437344b6..b7e8e87193 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -1,6 +1,7 @@ import os import re -from typing import TYPE_CHECKING, Any, Sequence +from collections.abc import Sequence +from typing import TYPE_CHECKING, Any from unittest import mock, skipUnless from urllib.parse import urlsplit diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index 520414dbb6..09f9f793b9 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -2,10 +2,11 @@ import base64 import email.policy import os import subprocess +from collections.abc import Callable, Mapping from email import message_from_string from email.headerregistry import Address from email.message import EmailMessage, MIMEPart -from typing import TYPE_CHECKING, Any, Callable, Mapping +from typing import TYPE_CHECKING, Any from unittest import mock import orjson diff --git a/zerver/tests/test_event_queue.py b/zerver/tests/test_event_queue.py index 5e4adf3763..8ca7ed2f19 100644 --- a/zerver/tests/test_event_queue.py +++ b/zerver/tests/test_event_queue.py @@ -1,5 +1,6 @@ import time -from typing import Any, Callable, Collection +from collections.abc import Callable, Collection +from typing import Any from unittest import mock import orjson diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py index 6c699d9b22..5039bf0474 100644 --- a/zerver/tests/test_event_system.py +++ b/zerver/tests/test_event_system.py @@ -1,5 +1,6 @@ import time -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from unittest import mock from urllib.parse import urlsplit diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 69a70bd27d..ad374c6f2b 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -6,10 +6,11 @@ # events; it also uses the OpenAPI tools to validate our documentation. import copy import time +from collections.abc import Iterator from contextlib import contextmanager from datetime import timedelta from io import StringIO -from typing import Any, Iterator +from typing import Any from unittest import mock import orjson diff --git a/zerver/tests/test_external.py b/zerver/tests/test_external.py index f99609dd76..cba84caf10 100644 --- a/zerver/tests/test_external.py +++ b/zerver/tests/test_external.py @@ -1,7 +1,8 @@ import time import uuid +from collections.abc import Callable, Iterator, Sequence from contextlib import contextmanager -from typing import IO, TYPE_CHECKING, Any, Callable, Iterator, Sequence +from typing import IO, TYPE_CHECKING, Any from unittest import mock, skipUnless import DNS diff --git a/zerver/tests/test_has_request_variables.py b/zerver/tests/test_has_request_variables.py index 2bfb494ffd..5f10c2301f 100644 --- a/zerver/tests/test_has_request_variables.py +++ b/zerver/tests/test_has_request_variables.py @@ -1,4 +1,5 @@ -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any import orjson from django.http import HttpRequest, HttpResponse diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index 0e62db8a2d..a7e9f82e0b 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -3,8 +3,9 @@ import os import shutil import uuid from collections import defaultdict +from collections.abc import Callable, Iterable from datetime import datetime, timedelta, timezone -from typing import Any, Callable, Iterable +from typing import Any from unittest.mock import patch import orjson diff --git a/zerver/tests/test_invite.py b/zerver/tests/test_invite.py index a91862df37..7c51f192c9 100644 --- a/zerver/tests/test_invite.py +++ b/zerver/tests/test_invite.py @@ -1,6 +1,7 @@ import re +from collections.abc import Sequence from datetime import datetime, timedelta -from typing import TYPE_CHECKING, Sequence +from typing import TYPE_CHECKING from unittest.mock import patch from urllib.parse import quote, urlencode diff --git a/zerver/tests/test_message_edit_notifications.py b/zerver/tests/test_message_edit_notifications.py index 006c6a74cb..03bdec64be 100644 --- a/zerver/tests/test_message_edit_notifications.py +++ b/zerver/tests/test_message_edit_notifications.py @@ -1,4 +1,5 @@ -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from unittest import mock from django.utils.timezone import now as timezone_now diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py index de2a251d32..d66742554c 100644 --- a/zerver/tests/test_message_fetch.py +++ b/zerver/tests/test_message_fetch.py @@ -1,6 +1,7 @@ +from collections.abc import Sequence from dataclasses import dataclass from datetime import timedelta -from typing import TYPE_CHECKING, Any, Sequence +from typing import TYPE_CHECKING, Any from unittest import mock import orjson diff --git a/zerver/tests/test_message_notification_emails.py b/zerver/tests/test_message_notification_emails.py index f37c0a5a45..5f280655b4 100644 --- a/zerver/tests/test_message_notification_emails.py +++ b/zerver/tests/test_message_notification_emails.py @@ -1,7 +1,7 @@ import random import re +from collections.abc import Sequence from email.headerregistry import Address -from typing import Sequence from unittest import mock from unittest.mock import patch diff --git a/zerver/tests/test_new_users.py b/zerver/tests/test_new_users.py index dc857c5eac..dc5ab1ddd4 100644 --- a/zerver/tests/test_new_users.py +++ b/zerver/tests/test_new_users.py @@ -1,5 +1,5 @@ +from collections.abc import Sequence from datetime import datetime, timedelta, timezone -from typing import Sequence import time_machine import zoneinfo diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py index 764e95fdfa..fd51f89c3d 100644 --- a/zerver/tests/test_openapi.py +++ b/zerver/tests/test_openapi.py @@ -2,7 +2,8 @@ import inspect import os import types from collections import abc -from typing import Any, Callable, Mapping, Sequence, Union, get_args, get_origin +from collections.abc import Callable, Mapping, Sequence +from typing import Any, Union, get_args, get_origin from unittest.mock import MagicMock, patch import yaml diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 1d1b3437f6..47d2254aca 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -2,9 +2,10 @@ import asyncio import base64 import logging import uuid +from collections.abc import Iterator, Mapping from contextlib import contextmanager from datetime import datetime, timedelta, timezone -from typing import Any, Iterator, Mapping +from typing import Any from unittest import mock, skipUnless import aioapns diff --git a/zerver/tests/test_queue_worker.py b/zerver/tests/test_queue_worker.py index 67e6151ab5..6a1bf7de41 100644 --- a/zerver/tests/test_queue_worker.py +++ b/zerver/tests/test_queue_worker.py @@ -3,9 +3,10 @@ import os import signal import time from collections import defaultdict +from collections.abc import Callable, Iterator, Mapping from contextlib import contextmanager, suppress from datetime import datetime, timedelta, timezone -from typing import Any, Callable, Iterator, Mapping +from typing import Any, TypeAlias from unittest.mock import MagicMock, patch import orjson @@ -13,7 +14,7 @@ import time_machine from django.conf import settings from django.db.utils import IntegrityError from django.test import override_settings -from typing_extensions import TypeAlias, override +from typing_extensions import override from zerver.lib.email_mirror import RateLimitedRealmMirror from zerver.lib.email_mirror_helpers import encode_email_address diff --git a/zerver/tests/test_scim.py b/zerver/tests/test_scim.py index 2b39b8ff26..284d746ec1 100644 --- a/zerver/tests/test_scim.py +++ b/zerver/tests/test_scim.py @@ -1,6 +1,7 @@ import copy +from collections.abc import Iterator from contextlib import contextmanager -from typing import TYPE_CHECKING, Any, Iterator, TypedDict +from typing import TYPE_CHECKING, Any, TypedDict from unittest import mock import orjson diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.py index 0c783d6385..bf701f4344 100644 --- a/zerver/tests/test_service_bot_system.py +++ b/zerver/tests/test_service_bot_system.py @@ -1,11 +1,12 @@ +from collections.abc import Callable from functools import wraps -from typing import Any, Callable +from typing import Any, Concatenate from unittest import mock import orjson from django.conf import settings from django.test import override_settings -from typing_extensions import Concatenate, ParamSpec, override +from typing_extensions import ParamSpec, override from zerver.actions.create_user import do_create_user from zerver.actions.message_send import get_service_bot_events diff --git a/zerver/tests/test_sessions.py b/zerver/tests/test_sessions.py index 6c371b7ed1..5f7cf8ace3 100644 --- a/zerver/tests/test_sessions.py +++ b/zerver/tests/test_sessions.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from datetime import timedelta -from typing import Any, Callable +from typing import Any import time_machine from django.utils.timezone import now as timezone_now diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 71f9d5ba5a..af023c5581 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -1,7 +1,8 @@ import re import time +from collections.abc import Sequence from datetime import timedelta -from typing import TYPE_CHECKING, Any, Sequence, Union +from typing import TYPE_CHECKING, Any, Union from unittest.mock import MagicMock, patch from urllib.parse import quote, quote_plus, urlencode, urlsplit diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py index 1ddf85ef0b..d6b9ca6614 100644 --- a/zerver/tests/test_slack_importer.py +++ b/zerver/tests/test_slack_importer.py @@ -1,7 +1,8 @@ import os import shutil +from collections.abc import Iterator from io import BytesIO -from typing import Any, Iterator +from typing import Any from unittest import mock from unittest.mock import ANY from urllib.parse import parse_qs, urlsplit diff --git a/zerver/tests/test_soft_deactivation.py b/zerver/tests/test_soft_deactivation.py index 8206bc668d..62f764e747 100644 --- a/zerver/tests/test_soft_deactivation.py +++ b/zerver/tests/test_soft_deactivation.py @@ -1,4 +1,4 @@ -from typing import AbstractSet +from collections.abc import Set as AbstractSet from unittest import mock from django.utils.timezone import now as timezone_now diff --git a/zerver/tests/test_subdomains.py b/zerver/tests/test_subdomains.py index e6047b07e0..b15dd51aa0 100644 --- a/zerver/tests/test_subdomains.py +++ b/zerver/tests/test_subdomains.py @@ -1,4 +1,5 @@ -from typing import Any, Mapping, Sequence +from collections.abc import Mapping, Sequence +from typing import Any from unittest import mock from django.conf import settings diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 56c2acf090..f8b858a240 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -1,8 +1,9 @@ import hashlib import random +from collections.abc import Sequence from datetime import timedelta from io import StringIO -from typing import TYPE_CHECKING, Any, Sequence +from typing import TYPE_CHECKING, Any from unittest import mock import orjson diff --git a/zerver/tests/test_tornado.py b/zerver/tests/test_tornado.py index 9cb253866f..c08883d3e6 100644 --- a/zerver/tests/test_tornado.py +++ b/zerver/tests/test_tornado.py @@ -1,7 +1,8 @@ import asyncio import socket +from collections.abc import Awaitable, Callable from functools import wraps -from typing import Any, Awaitable, Callable, TypeVar +from typing import Any, TypeVar from unittest import TestResult, mock from urllib.parse import urlencode diff --git a/zerver/tests/test_typed_endpoint.py b/zerver/tests/test_typed_endpoint.py index 7a7b985131..6d6ca67d32 100644 --- a/zerver/tests/test_typed_endpoint.py +++ b/zerver/tests/test_typed_endpoint.py @@ -1,4 +1,5 @@ -from typing import Any, Callable, Literal, TypeVar, cast +from collections.abc import Callable +from typing import Annotated, Any, Literal, TypeAlias, TypeVar, cast import orjson from django.core.exceptions import ValidationError as DjangoValidationError @@ -6,7 +7,7 @@ from django.http import HttpRequest, HttpResponse from pydantic import BaseModel, ConfigDict, Json, StringConstraints, ValidationInfo, WrapValidator from pydantic.dataclasses import dataclass from pydantic.functional_validators import ModelWrapValidatorHandler -from typing_extensions import Annotated, TypeAlias, override +from typing_extensions import override from zerver.lib.exceptions import ApiParamValidationError, JsonableError from zerver.lib.request import RequestConfusingParamsError, RequestVariableMissingError diff --git a/zerver/tests/test_user_groups.py b/zerver/tests/test_user_groups.py index 6d809477b2..a603bccbc0 100644 --- a/zerver/tests/test_user_groups.py +++ b/zerver/tests/test_user_groups.py @@ -1,5 +1,5 @@ +from collections.abc import Iterable from datetime import timedelta -from typing import Iterable from unittest import mock import orjson diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py index ca3fc2e339..22badd5f02 100644 --- a/zerver/tests/test_users.py +++ b/zerver/tests/test_users.py @@ -1,6 +1,7 @@ +from collections.abc import Iterable from datetime import timedelta from email.headerregistry import Address -from typing import Any, Iterable, TypeVar +from typing import Any, TypeVar from unittest import mock import orjson diff --git a/zerver/tornado/django_api.py b/zerver/tornado/django_api.py index fb3dde96f3..8d5c088301 100644 --- a/zerver/tornado/django_api.py +++ b/zerver/tornado/django_api.py @@ -1,6 +1,7 @@ from collections import defaultdict +from collections.abc import Iterable, Mapping, Sequence from functools import lru_cache -from typing import Any, Iterable, Mapping, Sequence +from typing import Any from urllib.parse import urlsplit import orjson diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index 637144e234..0a2c197a27 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -8,21 +8,11 @@ import time import traceback import uuid from collections import deque +from collections.abc import Callable, Collection, Iterable, Mapping, MutableMapping, Sequence +from collections.abc import Set as AbstractSet from contextlib import suppress from functools import cache -from typing import ( - AbstractSet, - Any, - Callable, - Collection, - Iterable, - Literal, - Mapping, - MutableMapping, - Sequence, - TypedDict, - cast, -) +from typing import Any, Literal, TypedDict, cast import orjson import tornado.ioloop diff --git a/zerver/tornado/handlers.py b/zerver/tornado/handlers.py index 82f0db2f55..235854d1cd 100644 --- a/zerver/tornado/handlers.py +++ b/zerver/tornado/handlers.py @@ -1,6 +1,7 @@ import logging +from collections.abc import Collection from contextlib import suppress -from typing import Any, Collection, Optional +from typing import Any, Optional from urllib.parse import unquote import tornado.web diff --git a/zerver/tornado/sharding.py b/zerver/tornado/sharding.py index c3b006a81b..e8f8a8555a 100644 --- a/zerver/tornado/sharding.py +++ b/zerver/tornado/sharding.py @@ -1,7 +1,7 @@ import json import os import re -from typing import Pattern +from re import Pattern from django.conf import settings diff --git a/zerver/tornado/views.py b/zerver/tornado/views.py index 2deff01eda..1543767b34 100644 --- a/zerver/tornado/views.py +++ b/zerver/tornado/views.py @@ -1,5 +1,6 @@ import time -from typing import Any, Callable, Mapping, Sequence, TypeVar +from collections.abc import Callable, Mapping, Sequence +from typing import Any, TypeVar from asgiref.sync import async_to_sync from django.conf import settings diff --git a/zerver/views/alert_words.py b/zerver/views/alert_words.py index df51d0799c..ab6cb9d544 100644 --- a/zerver/views/alert_words.py +++ b/zerver/views/alert_words.py @@ -1,6 +1,7 @@ +from typing import Annotated + from django.http import HttpRequest, HttpResponse from pydantic import Json, StringConstraints -from typing_extensions import Annotated from zerver.actions.alert_words import do_add_alert_words, do_remove_alert_words from zerver.lib.alert_words import user_alert_words diff --git a/zerver/views/auth.py b/zerver/views/auth.py index ad7bd1348a..2b8c93337c 100644 --- a/zerver/views/auth.py +++ b/zerver/views/auth.py @@ -1,7 +1,8 @@ import logging import secrets +from collections.abc import Callable, Mapping from functools import wraps -from typing import TYPE_CHECKING, Any, Callable, Mapping, cast +from typing import TYPE_CHECKING, Any, Concatenate, TypeAlias, cast from urllib.parse import urlencode, urljoin import jwt @@ -25,7 +26,7 @@ from django.views.decorators.http import require_safe from social_django.utils import load_backend, load_strategy from two_factor.forms import BackupTokenForm from two_factor.views import LoginView as BaseTwoFactorLoginView -from typing_extensions import Concatenate, ParamSpec, TypeAlias +from typing_extensions import ParamSpec from confirmation.models import ( Confirmation, diff --git a/zerver/views/documentation.py b/zerver/views/documentation.py index 801142f935..3617d69538 100644 --- a/zerver/views/documentation.py +++ b/zerver/views/documentation.py @@ -2,8 +2,9 @@ import os import random import re from collections import OrderedDict +from collections.abc import Callable from dataclasses import dataclass -from typing import Any, Callable +from typing import Any from django.conf import settings from django.http import HttpRequest, HttpResponse, HttpResponseNotFound diff --git a/zerver/views/events_register.py b/zerver/views/events_register.py index 7fb12ee7b8..1a438efb05 100644 --- a/zerver/views/events_register.py +++ b/zerver/views/events_register.py @@ -1,10 +1,10 @@ -from typing import Sequence +from collections.abc import Sequence +from typing import TypeAlias from django.conf import settings from django.contrib.auth.models import AnonymousUser from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ -from typing_extensions import TypeAlias from zerver.context_processors import get_valid_realm_from_request from zerver.lib.compatibility import is_pronouns_field_type_supported diff --git a/zerver/views/invite.py b/zerver/views/invite.py index 2efcd06ce4..8b65ee8faf 100644 --- a/zerver/views/invite.py +++ b/zerver/views/invite.py @@ -1,5 +1,5 @@ import re -from typing import Sequence +from collections.abc import Sequence from django.conf import settings from django.http import HttpRequest, HttpResponse diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.py index 09f2c842b9..2cd06c0795 100644 --- a/zerver/views/message_fetch.py +++ b/zerver/views/message_fetch.py @@ -1,4 +1,5 @@ -from typing import Iterable +from collections.abc import Iterable +from typing import Annotated from django.conf import settings from django.contrib.auth.models import AnonymousUser @@ -9,7 +10,6 @@ from django.utils.translation import gettext as _ from pydantic import Json, NonNegativeInt from sqlalchemy.sql import and_, column, join, literal, literal_column, select, table from sqlalchemy.types import Integer, Text -from typing_extensions import Annotated from zerver.context_processors import get_valid_realm_from_request from zerver.lib.exceptions import JsonableError, MissingAuthenticationError diff --git a/zerver/views/message_flags.py b/zerver/views/message_flags.py index 9e5c3288ea..04f2779352 100644 --- a/zerver/views/message_flags.py +++ b/zerver/views/message_flags.py @@ -1,7 +1,8 @@ +from typing import Annotated + from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ from pydantic import Json, NonNegativeInt -from typing_extensions import Annotated from zerver.actions.message_flags import ( do_mark_all_as_read, diff --git a/zerver/views/message_send.py b/zerver/views/message_send.py index 490233e993..8837d0f512 100644 --- a/zerver/views/message_send.py +++ b/zerver/views/message_send.py @@ -1,5 +1,6 @@ +from collections.abc import Iterable, Sequence from email.headerregistry import Address -from typing import Iterable, Sequence, cast +from typing import cast from django.core import validators from django.core.exceptions import ValidationError diff --git a/zerver/views/presence.py b/zerver/views/presence.py index de79790327..0813712002 100644 --- a/zerver/views/presence.py +++ b/zerver/views/presence.py @@ -1,12 +1,11 @@ from datetime import timedelta -from typing import Any +from typing import Annotated, Any from django.conf import settings from django.http import HttpRequest, HttpResponse from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from pydantic import Json, StringConstraints -from typing_extensions import Annotated from zerver.actions.presence import update_user_presence from zerver.actions.user_status import do_update_user_status diff --git a/zerver/views/realm.py b/zerver/views/realm.py index 4f3295899b..9dc074296c 100644 --- a/zerver/views/realm.py +++ b/zerver/views/realm.py @@ -1,4 +1,5 @@ -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Annotated, Any from django.core.exceptions import ValidationError from django.db import transaction @@ -8,7 +9,6 @@ from django.utils.translation import gettext as _ from django.views.decorators.http import require_safe from pydantic import Json, NonNegativeInt, StringConstraints from pydantic.functional_validators import AfterValidator -from typing_extensions import Annotated from confirmation.models import Confirmation, ConfirmationKeyError, get_object_from_key from zerver.actions.create_realm import do_change_realm_subdomain diff --git a/zerver/views/registration.py b/zerver/views/registration.py index 0053dfbb9d..70fc282650 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -1,6 +1,7 @@ import logging +from collections.abc import Iterable from contextlib import suppress -from typing import Any, Iterable +from typing import Any from urllib.parse import urlencode, urljoin import orjson diff --git a/zerver/views/streams.py b/zerver/views/streams.py index 287ed0a7b9..2deb5c5233 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -1,6 +1,7 @@ import time from collections import defaultdict -from typing import Any, Callable, Mapping, Sequence +from collections.abc import Callable, Mapping, Sequence +from typing import Any import orjson from django.conf import settings diff --git a/zerver/views/tutorial.py b/zerver/views/tutorial.py index e5745147d0..70502f9d58 100644 --- a/zerver/views/tutorial.py +++ b/zerver/views/tutorial.py @@ -1,5 +1,6 @@ +from typing import Literal + from django.http import HttpRequest, HttpResponse -from typing_extensions import Literal from zerver.decorator import human_users_only from zerver.lib.response import json_success diff --git a/zerver/views/typing.py b/zerver/views/typing.py index 3e146302ff..2285206626 100644 --- a/zerver/views/typing.py +++ b/zerver/views/typing.py @@ -1,7 +1,8 @@ +from typing import Annotated, Literal + from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ from pydantic import Json -from typing_extensions import Annotated, Literal from zerver.actions.typing import check_send_typing_notification, do_send_stream_typing_notification from zerver.lib.exceptions import JsonableError diff --git a/zerver/views/unsubscribe.py b/zerver/views/unsubscribe.py index f2ac39d65f..b4716a6f73 100644 --- a/zerver/views/unsubscribe.py +++ b/zerver/views/unsubscribe.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from django.http import HttpRequest, HttpResponse from django.shortcuts import render diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index 175b59fa9b..c1caec2b6c 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -1,4 +1,4 @@ -from typing import Sequence +from collections.abc import Sequence from django.conf import settings from django.db import transaction diff --git a/zerver/views/user_topics.py b/zerver/views/user_topics.py index 9ce044e2eb..2bf913d122 100644 --- a/zerver/views/user_topics.py +++ b/zerver/views/user_topics.py @@ -1,10 +1,10 @@ from datetime import datetime +from typing import Annotated, Literal from django.http import HttpRequest, HttpResponse from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from pydantic import AfterValidator, Json, StringConstraints -from typing_extensions import Annotated, Literal from zerver.actions.user_topics import do_set_user_topic_visibility_policy from zerver.lib.response import json_success diff --git a/zerver/views/users.py b/zerver/views/users.py index 815dfd18b9..419035baff 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -1,5 +1,6 @@ +from collections.abc import Mapping from email.headerregistry import Address -from typing import Any, Mapping, TypeAlias +from typing import Annotated, Any, TypeAlias from django.conf import settings from django.contrib.auth.models import AnonymousUser @@ -8,7 +9,6 @@ from django.http import HttpRequest, HttpResponse from django.shortcuts import redirect from django.utils.translation import gettext as _ from pydantic import AfterValidator, BaseModel, Json, StringConstraints -from typing_extensions import Annotated from zerver.actions.bots import ( do_change_bot_owner, diff --git a/zerver/webhooks/alertmanager/view.py b/zerver/webhooks/alertmanager/view.py index 850392c5d1..cea1183262 100644 --- a/zerver/webhooks/alertmanager/view.py +++ b/zerver/webhooks/alertmanager/view.py @@ -1,7 +1,8 @@ # Webhooks for external integrations. +from typing import Annotated + from django.http import HttpRequest, HttpResponse -from typing_extensions import Annotated from zerver.decorator import webhook_view from zerver.lib.response import json_success diff --git a/zerver/webhooks/azuredevops/view.py b/zerver/webhooks/azuredevops/view.py index caeb658dcf..228da64e13 100644 --- a/zerver/webhooks/azuredevops/view.py +++ b/zerver/webhooks/azuredevops/view.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.py index f1c4dfd463..acdb6e0d8b 100644 --- a/zerver/webhooks/clubhouse/view.py +++ b/zerver/webhooks/clubhouse/view.py @@ -1,4 +1,4 @@ -from typing import Callable, Iterable, Iterator +from collections.abc import Callable, Iterable, Iterator from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/front/view.py b/zerver/webhooks/front/view.py index f43de3986d..b7f826161f 100644 --- a/zerver/webhooks/front/view.py +++ b/zerver/webhooks/front/view.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index 3112cc2494..ee10e23ed6 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -1,6 +1,6 @@ import re +from collections.abc import Callable from datetime import datetime, timezone -from typing import Callable from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/groove/view.py b/zerver/webhooks/groove/view.py index 2b9dd7d768..e8c7c8bec6 100644 --- a/zerver/webhooks/groove/view.py +++ b/zerver/webhooks/groove/view.py @@ -1,5 +1,5 @@ # Webhooks for external integrations. -from typing import Callable +from collections.abc import Callable from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/hellosign/view.py b/zerver/webhooks/hellosign/view.py index 108c5dfa86..1e9ed88189 100644 --- a/zerver/webhooks/hellosign/view.py +++ b/zerver/webhooks/hellosign/view.py @@ -1,6 +1,7 @@ +from typing import Annotated + from django.http import HttpRequest, HttpResponse from pydantic import Json -from typing_extensions import Annotated from zerver.decorator import webhook_view from zerver.lib.response import json_success diff --git a/zerver/webhooks/intercom/view.py b/zerver/webhooks/intercom/view.py index a40978b8f6..3b2b2823aa 100644 --- a/zerver/webhooks/intercom/view.py +++ b/zerver/webhooks/intercom/view.py @@ -1,5 +1,5 @@ +from collections.abc import Callable from html.parser import HTMLParser -from typing import Callable from django.http import HttpRequest, HttpResponse from typing_extensions import override diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.py index d37dd3f5df..3bfdde2bf0 100644 --- a/zerver/webhooks/jira/view.py +++ b/zerver/webhooks/jira/view.py @@ -1,7 +1,7 @@ # Webhooks for external integrations. import re import string -from typing import Callable +from collections.abc import Callable from django.core.exceptions import ValidationError from django.db.models import Q diff --git a/zerver/webhooks/librato/view.py b/zerver/webhooks/librato/view.py index cdc96dee62..3e45bfb96a 100644 --- a/zerver/webhooks/librato/view.py +++ b/zerver/webhooks/librato/view.py @@ -1,5 +1,6 @@ +from collections.abc import Callable, Mapping from datetime import datetime, timezone -from typing import Any, Callable, Mapping +from typing import Any import orjson from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/linear/view.py b/zerver/webhooks/linear/view.py index e3b82b5b97..f32caca362 100644 --- a/zerver/webhooks/linear/view.py +++ b/zerver/webhooks/linear/view.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/pagerduty/view.py b/zerver/webhooks/pagerduty/view.py index 8fd131ee9d..0c08d80c07 100644 --- a/zerver/webhooks/pagerduty/view.py +++ b/zerver/webhooks/pagerduty/view.py @@ -1,7 +1,7 @@ from email.headerregistry import Address +from typing import TypeAlias from django.http import HttpRequest, HttpResponse -from typing_extensions import TypeAlias from zerver.decorator import webhook_view from zerver.lib.exceptions import UnsupportedWebhookEventTypeError diff --git a/zerver/webhooks/patreon/view.py b/zerver/webhooks/patreon/view.py index b433268c5a..eb43682516 100644 --- a/zerver/webhooks/patreon/view.py +++ b/zerver/webhooks/patreon/view.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/rhodecode/view.py b/zerver/webhooks/rhodecode/view.py index 77e693bd41..2795fc1336 100644 --- a/zerver/webhooks/rhodecode/view.py +++ b/zerver/webhooks/rhodecode/view.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from django.core.exceptions import ValidationError from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/stripe/view.py b/zerver/webhooks/stripe/view.py index 0e80938857..fa810e3274 100644 --- a/zerver/webhooks/stripe/view.py +++ b/zerver/webhooks/stripe/view.py @@ -1,6 +1,6 @@ # Webhooks for external integrations. import time -from typing import Sequence +from collections.abc import Sequence from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/taiga/view.py b/zerver/webhooks/taiga/view.py index ba8f2231ff..893bc19f43 100644 --- a/zerver/webhooks/taiga/view.py +++ b/zerver/webhooks/taiga/view.py @@ -7,8 +7,9 @@ value should always be in bold; otherwise the subject of US/task should be in bold. """ +from typing import TypeAlias + from django.http import HttpRequest, HttpResponse -from typing_extensions import TypeAlias from zerver.decorator import webhook_view from zerver.lib.response import json_success diff --git a/zerver/webhooks/travis/view.py b/zerver/webhooks/travis/view.py index cb2f4844e9..b79aaa4f95 100644 --- a/zerver/webhooks/travis/view.py +++ b/zerver/webhooks/travis/view.py @@ -1,8 +1,9 @@ # Webhooks for external integrations. +from typing import Annotated + from django.http import HttpRequest, HttpResponse from pydantic import BaseModel, Json -from typing_extensions import Annotated from zerver.decorator import webhook_view from zerver.lib.response import json_success diff --git a/zerver/webhooks/trello/view/board_actions.py b/zerver/webhooks/trello/view/board_actions.py index d69e70c1fe..8430958e3c 100644 --- a/zerver/webhooks/trello/view/board_actions.py +++ b/zerver/webhooks/trello/view/board_actions.py @@ -1,4 +1,4 @@ -from typing import Mapping +from collections.abc import Mapping from zerver.lib.exceptions import UnsupportedWebhookEventTypeError from zerver.lib.validator import WildValue, check_string diff --git a/zerver/webhooks/trello/view/card_actions.py b/zerver/webhooks/trello/view/card_actions.py index da0fcd3be7..e238da4403 100644 --- a/zerver/webhooks/trello/view/card_actions.py +++ b/zerver/webhooks/trello/view/card_actions.py @@ -1,4 +1,4 @@ -from typing import Mapping +from collections.abc import Mapping from zerver.lib.exceptions import UnsupportedWebhookEventTypeError from zerver.lib.validator import WildValue, check_bool, check_none_or, check_string diff --git a/zerver/worker/base.py b/zerver/worker/base.py index a6e1d009cc..665fb86c33 100644 --- a/zerver/worker/base.py +++ b/zerver/worker/base.py @@ -5,8 +5,9 @@ import signal import time from abc import ABC, abstractmethod from collections import deque +from collections.abc import Callable, MutableSequence from types import FrameType -from typing import Any, Callable, MutableSequence, TypeVar +from typing import Any, TypeVar import orjson import sentry_sdk diff --git a/zerver/worker/digest_emails.py b/zerver/worker/digest_emails.py index 8d3c2749b0..058aef762d 100644 --- a/zerver/worker/digest_emails.py +++ b/zerver/worker/digest_emails.py @@ -1,6 +1,7 @@ # Documented in https://zulip.readthedocs.io/en/latest/subsystems/queuing.html import logging -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from typing_extensions import override diff --git a/zerver/worker/email_mirror.py b/zerver/worker/email_mirror.py index 94da59e5bc..b2b6cb3496 100644 --- a/zerver/worker/email_mirror.py +++ b/zerver/worker/email_mirror.py @@ -3,8 +3,9 @@ import base64 import email import email.policy import logging +from collections.abc import Mapping from email.message import EmailMessage -from typing import Any, Mapping +from typing import Any from typing_extensions import override diff --git a/zerver/worker/email_senders.py b/zerver/worker/email_senders.py index 5689d6ee15..f4c1206a9b 100644 --- a/zerver/worker/email_senders.py +++ b/zerver/worker/email_senders.py @@ -2,8 +2,9 @@ import copy import logging import socket +from collections.abc import Callable from functools import wraps -from typing import Any, Callable +from typing import Any from django.core.mail.backends.base import BaseEmailBackend from typing_extensions import override diff --git a/zerver/worker/embed_links.py b/zerver/worker/embed_links.py index 86b001eff5..29dbe79230 100644 --- a/zerver/worker/embed_links.py +++ b/zerver/worker/embed_links.py @@ -1,8 +1,9 @@ # Documented in https://zulip.readthedocs.io/en/latest/subsystems/queuing.html import logging import time +from collections.abc import Mapping from types import FrameType -from typing import Any, Mapping +from typing import Any from django.db import transaction from typing_extensions import override diff --git a/zerver/worker/embedded_bots.py b/zerver/worker/embedded_bots.py index b6d21e97ad..7660cc3010 100644 --- a/zerver/worker/embedded_bots.py +++ b/zerver/worker/embedded_bots.py @@ -1,6 +1,7 @@ # Documented in https://zulip.readthedocs.io/en/latest/subsystems/queuing.html import logging -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from typing_extensions import override from zulip_bots.lib import extract_query_without_mention diff --git a/zerver/worker/test.py b/zerver/worker/test.py index 2faf04b6e6..bd90b704fe 100644 --- a/zerver/worker/test.py +++ b/zerver/worker/test.py @@ -1,7 +1,8 @@ # Documented in https://zulip.readthedocs.io/en/latest/subsystems/queuing.html import logging import time -from typing import Any, Mapping, Sequence +from collections.abc import Mapping, Sequence +from typing import Any import orjson from django.conf import settings diff --git a/zerver/worker/user_activity_interval.py b/zerver/worker/user_activity_interval.py index 2e3a8b1b8d..b0b0e52e8f 100644 --- a/zerver/worker/user_activity_interval.py +++ b/zerver/worker/user_activity_interval.py @@ -1,6 +1,7 @@ # Documented in https://zulip.readthedocs.io/en/latest/subsystems/queuing.html import logging -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from typing_extensions import override diff --git a/zerver/worker/user_presence.py b/zerver/worker/user_presence.py index 86a49428db..5239643dd7 100644 --- a/zerver/worker/user_presence.py +++ b/zerver/worker/user_presence.py @@ -1,6 +1,7 @@ # Documented in https://zulip.readthedocs.io/en/latest/subsystems/queuing.html import logging -from typing import Any, Mapping +from collections.abc import Mapping +from typing import Any from typing_extensions import override diff --git a/zilencer/auth.py b/zilencer/auth.py index 35b4d57934..b11635ffd2 100644 --- a/zilencer/auth.py +++ b/zilencer/auth.py @@ -1,6 +1,7 @@ import logging +from collections.abc import Callable from functools import wraps -from typing import Any, Callable +from typing import Any, Concatenate import sentry_sdk from django.conf import settings @@ -11,7 +12,7 @@ from django.utils.crypto import constant_time_compare from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from django.views.decorators.csrf import csrf_exempt -from typing_extensions import Concatenate, ParamSpec, override +from typing_extensions import ParamSpec, override from zerver.decorator import get_basic_credentials, process_client from zerver.lib.exceptions import ( diff --git a/zilencer/management/commands/calculate_first_visible_message_id.py b/zilencer/management/commands/calculate_first_visible_message_id.py index 70aab76fdd..470b6676c8 100644 --- a/zilencer/management/commands/calculate_first_visible_message_id.py +++ b/zilencer/management/commands/calculate_first_visible_message_id.py @@ -1,4 +1,5 @@ -from typing import Any, Iterable +from collections.abc import Iterable +from typing import Any from django.core.management.base import CommandParser from typing_extensions import override diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index bdd6f973d8..4abfc3f80a 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -2,8 +2,9 @@ import itertools import os import random from collections import defaultdict +from collections.abc import Mapping, Sequence from datetime import datetime, timedelta -from typing import Any, Mapping, Sequence +from typing import Any import bmemcached import orjson diff --git a/zilencer/management/commands/render_messages.py b/zilencer/management/commands/render_messages.py index 897c80c971..2828cbf829 100644 --- a/zilencer/management/commands/render_messages.py +++ b/zilencer/management/commands/render_messages.py @@ -1,5 +1,6 @@ import os -from typing import Any, Iterator +from collections.abc import Iterator +from typing import Any import orjson from django.core.management.base import CommandParser diff --git a/zilencer/management/commands/rundjangoserver.py b/zilencer/management/commands/rundjangoserver.py index 6426534e1e..f3b2da8ffc 100644 --- a/zilencer/management/commands/rundjangoserver.py +++ b/zilencer/management/commands/rundjangoserver.py @@ -1,6 +1,6 @@ +from collections.abc import Callable from datetime import datetime from functools import wraps -from typing import Callable from dateutil.tz import tzlocal from django.core.management.commands.runserver import Command as DjangoCommand diff --git a/zilencer/migrations/0027_backfill_remote_realmauditlog_extradata_to_json_field.py b/zilencer/migrations/0027_backfill_remote_realmauditlog_extradata_to_json_field.py index b37d647126..52679de6b3 100644 --- a/zilencer/migrations/0027_backfill_remote_realmauditlog_extradata_to_json_field.py +++ b/zilencer/migrations/0027_backfill_remote_realmauditlog_extradata_to_json_field.py @@ -1,7 +1,7 @@ # Generated by Django 4.0.7 on 2022-09-30 20:30 import ast -from typing import Callable +from collections.abc import Callable import orjson from django.db import migrations, transaction diff --git a/zilencer/views.py b/zilencer/views.py index cbdb6abe4f..f0dab525b3 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -2,7 +2,7 @@ import logging from collections import Counter from datetime import datetime, timezone from email.headerregistry import Address -from typing import Any, TypedDict, TypeVar +from typing import Annotated, Any, TypedDict, TypeVar from uuid import UUID import orjson @@ -21,7 +21,6 @@ from dns import resolver as dns_resolver from dns.exception import DNSException from pydantic import BaseModel, ConfigDict, Json, StringConstraints from pydantic.functional_validators import AfterValidator -from typing_extensions import Annotated from analytics.lib.counts import ( BOUNCER_ONLY_REMOTE_COUNT_STAT_PROPERTIES, diff --git a/zproject/backends.py b/zproject/backends.py index 8a910f4056..0761959f4a 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -16,8 +16,9 @@ import binascii import json import logging from abc import ABC, abstractmethod +from collections.abc import Callable from email.headerregistry import Address -from typing import Any, Callable, TypedDict, TypeVar, cast +from typing import Any, TypedDict, TypeVar, cast from urllib.parse import urlencode import magic diff --git a/zproject/default_settings.py b/zproject/default_settings.py index 3f30738a20..e465952689 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -1,6 +1,7 @@ import os +from collections.abc import Callable from email.headerregistry import Address -from typing import TYPE_CHECKING, Any, Callable, Literal, Optional +from typing import TYPE_CHECKING, Any, Literal, Optional from django_auth_ldap.config import GroupOfUniqueNamesType, LDAPGroupType diff --git a/zproject/email_backends.py b/zproject/email_backends.py index 5bbd406253..9651708242 100644 --- a/zproject/email_backends.py +++ b/zproject/email_backends.py @@ -1,8 +1,8 @@ # https://zulip.readthedocs.io/en/latest/subsystems/email.html#testing-in-a-real-email-client import configparser import logging +from collections.abc import MutableSequence, Sequence from email.message import Message -from typing import MutableSequence, Sequence from django.conf import settings from django.core.mail import EmailMultiAlternatives