diff --git a/confirmation/models.py b/confirmation/models.py index ac5d66c590..bf1492bd4a 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -4,7 +4,7 @@ __revision__ = "$Id: models.py 28 2009-10-22 15:03:02Z jarek.zgoda $" import datetime import secrets from base64 import b32encode -from typing import List, Mapping, Optional, Union +from typing import List, Mapping, Optional, Protocol, Union from urllib.parse import urljoin from django.conf import settings @@ -16,7 +16,6 @@ from django.http import HttpRequest, HttpResponse from django.shortcuts import render from django.urls import reverse from django.utils.timezone import now as timezone_now -from typing_extensions import Protocol from zerver.lib.types import UnspecifiedValue from zerver.models import EmailChangeStatus, MultiuseInvite, PreregistrationUser, Realm, UserProfile diff --git a/requirements/common.in b/requirements/common.in index bc26ed1e68..6db6d0ff5d 100644 --- a/requirements/common.in +++ b/requirements/common.in @@ -5,7 +5,7 @@ # Django itself Django[argon2]==3.2.* -# needed for Literal, TypedDict +# needed for NotRequired, ParamSpec typing-extensions # Needed for rendering backend templates diff --git a/tools/fetch-contributor-data b/tools/fetch-contributor-data index cefc798a35..7023be4520 100755 --- a/tools/fetch-contributor-data +++ b/tools/fetch-contributor-data @@ -18,9 +18,10 @@ from scripts.lib.setup_path import setup_path setup_path() os.environ["DJANGO_SETTINGS_MODULE"] = "zproject.settings" +from typing import TypedDict + import django from django.conf import settings -from typing_extensions import TypedDict from urllib3.util import Retry django.setup() diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py index c710a6f02a..cae4e81b1b 100644 --- a/zerver/actions/message_edit.py +++ b/zerver/actions/message_edit.py @@ -1,5 +1,5 @@ import datetime -from typing import Any, Dict, Iterable, List, Optional, Set +from typing import Any, Dict, Iterable, List, Optional, Set, TypedDict from django.conf import settings from django.db import transaction @@ -7,7 +7,6 @@ from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy from django.utils.translation import override as override_language -from typing_extensions import TypedDict from zerver.actions.message_flags import do_update_mobile_push_notification from zerver.actions.message_send import ( diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py index c51fb803b2..fe4ce955da 100644 --- a/zerver/actions/message_send.py +++ b/zerver/actions/message_send.py @@ -12,6 +12,7 @@ from typing import ( Sequence, Set, Tuple, + TypedDict, Union, ) @@ -24,7 +25,6 @@ from django.utils.html import escape 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 typing_extensions import TypedDict from zerver.actions.uploads import do_claim_attachments from zerver.lib.addressee import Addressee diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py index f3548919d8..d64473d5aa 100644 --- a/zerver/data_import/import_util.py +++ b/zerver/data_import/import_util.py @@ -4,12 +4,23 @@ import os import random import shutil from functools import partial -from typing import AbstractSet, Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, TypeVar +from typing import ( + AbstractSet, + Any, + Callable, + Dict, + Iterable, + List, + Optional, + Protocol, + Set, + Tuple, + TypeVar, +) import orjson import requests from django.forms.models import model_to_dict -from typing_extensions import Protocol from zerver.data_import.sequencer import NEXT_ID from zerver.lib.avatar_hash import user_avatar_path_from_ids diff --git a/zerver/lib/display_recipient.py b/zerver/lib/display_recipient.py index 75d3439b0e..f6ed0c1d45 100644 --- a/zerver/lib/display_recipient.py +++ b/zerver/lib/display_recipient.py @@ -1,6 +1,4 @@ -from typing import Dict, List, Optional, Set, Tuple - -from typing_extensions import TypedDict +from typing import Dict, List, Optional, Set, Tuple, TypedDict from zerver.lib.cache import ( bulk_cached_fetch, diff --git a/zerver/lib/export.py b/zerver/lib/export.py index a49bbce948..6b147f20db 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -14,7 +14,7 @@ import shutil import subprocess import tempfile from functools import lru_cache -from typing import Any, Callable, Dict, List, Optional, Set, Tuple +from typing import Any, Callable, Dict, List, Optional, Set, Tuple, TypedDict import orjson from django.apps import apps @@ -24,7 +24,6 @@ from django.forms.models import model_to_dict from django.utils.timezone import is_naive as timezone_is_naive from django.utils.timezone import make_aware as timezone_make_aware from mypy_boto3_s3.service_resource import Object -from typing_extensions import TypedDict import zerver.lib.upload from analytics.models import RealmCount, StreamCount, UserCount diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index e8376fbd17..ee904283dc 100644 --- a/zerver/lib/markdown/__init__.py +++ b/zerver/lib/markdown/__init__.py @@ -21,6 +21,7 @@ from typing import ( Pattern, Set, Tuple, + TypedDict, TypeVar, Union, ) @@ -45,7 +46,6 @@ from markdown.blockparser import BlockParser from markdown.extensions import codehilite, nl2br, sane_lists, tables from soupsieve import escape as css_escape from tlds import tld_set -from typing_extensions import TypedDict from zerver.lib import mention as mention from zerver.lib.cache import cache_with_key diff --git a/zerver/lib/message.py b/zerver/lib/message.py index 770c0163e7..0d4a0cb178 100644 --- a/zerver/lib/message.py +++ b/zerver/lib/message.py @@ -2,7 +2,7 @@ import copy import datetime import zlib from dataclasses import dataclass, field -from typing import Any, Dict, List, Mapping, Optional, Sequence, Set, Tuple, Union +from typing import Any, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypedDict, Union import ahocorasick import orjson @@ -12,7 +12,6 @@ from django.db.models import Max, Sum from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from psycopg2.sql import SQL -from typing_extensions import TypedDict from analytics.lib.counts import COUNT_STATS from analytics.models import RealmCount diff --git a/zerver/lib/request.py b/zerver/lib/request.py index 989f5818a4..04eb75e65d 100644 --- a/zerver/lib/request.py +++ b/zerver/lib/request.py @@ -10,6 +10,7 @@ from typing import ( Dict, Generic, List, + Literal, MutableMapping, Optional, Sequence, @@ -24,7 +25,6 @@ import orjson from django.core.exceptions import ValidationError from django.http import HttpRequest, HttpResponse from django.utils.translation import gettext as _ -from typing_extensions import Literal import zerver.lib.rate_limiter as rate_limiter import zerver.tornado.handlers as handlers diff --git a/zerver/lib/sessions.py b/zerver/lib/sessions.py index 00eab8b210..d68e2f1982 100644 --- a/zerver/lib/sessions.py +++ b/zerver/lib/sessions.py @@ -1,14 +1,13 @@ import logging from datetime import timedelta from importlib import import_module -from typing import Any, List, Mapping, Optional, Type, cast +from typing import Any, List, Mapping, Optional, Protocol, Type, cast from django.conf import settings from django.contrib.auth import SESSION_KEY, get_user_model from django.contrib.sessions.backends.base import SessionBase from django.contrib.sessions.models import Session from django.utils.timezone import now as timezone_now -from typing_extensions import Protocol from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime from zerver.models import Realm, UserProfile, get_user_profile_by_id diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index 56cdaaf210..0d8a12542c 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -1,11 +1,10 @@ -from typing import Any, Collection, Dict, List, Optional, Set, Tuple, Union +from typing import Any, Collection, Dict, List, Optional, Set, Tuple, TypedDict, Union from django.db import transaction from django.db.models import Exists, OuterRef, Q from django.db.models.query import QuerySet from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ -from typing_extensions import TypedDict from zerver.actions.default_streams import get_default_streams_for_realm from zerver.lib.exceptions import ( diff --git a/zerver/lib/types.py b/zerver/lib/types.py index f585faf8c1..8f41a453d7 100644 --- a/zerver/lib/types.py +++ b/zerver/lib/types.py @@ -1,10 +1,10 @@ import datetime from dataclasses import dataclass -from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union +from typing import Any, Callable, Dict, List, Optional, Tuple, TypedDict, TypeVar, Union from django.http import HttpResponse from django.utils.functional import Promise -from typing_extensions import NotRequired, TypedDict +from typing_extensions import NotRequired ViewFuncT = TypeVar("ViewFuncT", bound=Callable[..., HttpResponse]) diff --git a/zerver/lib/url_preview/types.py b/zerver/lib/url_preview/types.py index ad235cbe03..853a535555 100644 --- a/zerver/lib/url_preview/types.py +++ b/zerver/lib/url_preview/types.py @@ -1,7 +1,5 @@ from dataclasses import dataclass -from typing import Optional - -from typing_extensions import Literal +from typing import Literal, Optional @dataclass diff --git a/zerver/lib/users.py b/zerver/lib/users.py index 6d6bc3a27c..fe8636df6d 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -1,7 +1,7 @@ import re import unicodedata from collections import defaultdict -from typing import Any, Dict, List, Optional, Sequence, Union, cast +from typing import Any, Dict, List, Optional, Sequence, TypedDict, Union, cast import dateutil.parser as date_parser from django.conf import settings @@ -9,7 +9,6 @@ from django.core.exceptions import ValidationError from django.db.models.query import QuerySet from django.forms.models import model_to_dict from django.utils.translation import gettext as _ -from typing_extensions import TypedDict from zulip_bots.custom_exceptions import ConfigValidationError from zerver.lib.avatar import avatar_url, get_avatar_field diff --git a/zerver/logging_handlers.py b/zerver/logging_handlers.py index e38e8fe24d..77782dc813 100644 --- a/zerver/logging_handlers.py +++ b/zerver/logging_handlers.py @@ -4,7 +4,7 @@ import os import platform import subprocess import traceback -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Protocol, runtime_checkable from urllib.parse import SplitResult from django.conf import settings @@ -12,7 +12,6 @@ from django.http import HttpRequest from django.utils.translation import override as override_language from django.views.debug import get_exception_reporter_filter from sentry_sdk import capture_exception -from typing_extensions import Protocol, runtime_checkable from version import ZULIP_VERSION from zerver.lib.logging_util import find_log_caller_module diff --git a/zerver/migrations/0377_message_edit_history_format.py b/zerver/migrations/0377_message_edit_history_format.py index 428b200859..223c4e325b 100644 --- a/zerver/migrations/0377_message_edit_history_format.py +++ b/zerver/migrations/0377_message_edit_history_format.py @@ -1,12 +1,11 @@ import time -from typing import List, Optional +from typing import List, Optional, TypedDict import orjson from django.db import migrations, transaction from django.db.backends.postgresql.schema import DatabaseSchemaEditor from django.db.migrations.state import StateApps from django.db.models import Min, Model -from typing_extensions import TypedDict BATCH_SIZE = 10000 STREAM = 2 diff --git a/zerver/models.py b/zerver/models.py index 5817e8f058..79e6657ab0 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -14,6 +14,7 @@ from typing import ( Sequence, Set, Tuple, + TypedDict, TypeVar, Union, ) @@ -48,7 +49,6 @@ from django.utils.timezone import now as timezone_now from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy from django_cte import CTEManager -from typing_extensions import TypedDict from confirmation import settings as confirmation_settings from zerver.lib import cache diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index 72d8ba048f..860ac5874d 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -28,6 +28,7 @@ from typing import ( Sequence, Set, Tuple, + TypedDict, Union, cast, ) @@ -36,7 +37,6 @@ import orjson import tornado.ioloop from django.conf import settings from django.utils.translation import gettext as _ -from typing_extensions import TypedDict from version import API_FEATURE_LEVEL, ZULIP_MERGE_BASE, ZULIP_VERSION from zerver.lib.exceptions import JsonableError diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.py index 1ea5d6cef7..f89249ec3a 100644 --- a/zerver/webhooks/bitbucket2/view.py +++ b/zerver/webhooks/bitbucket2/view.py @@ -2,10 +2,9 @@ import re import string from functools import partial -from typing import Dict, List, Optional +from typing import Dict, List, Optional, Protocol from django.http import HttpRequest, HttpResponse -from typing_extensions import Protocol from zerver.decorator import log_unsupported_webhook_event, webhook_view from zerver.lib.exceptions import UnsupportedWebhookEventType diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.py index d8775ac61c..774863ad9b 100644 --- a/zerver/webhooks/bitbucket3/view.py +++ b/zerver/webhooks/bitbucket3/view.py @@ -1,9 +1,8 @@ import string from functools import partial -from typing import Dict, List, Optional +from typing import Dict, List, Optional, Protocol from django.http import HttpRequest, HttpResponse -from typing_extensions import Protocol from zerver.decorator import webhook_view from zerver.lib.exceptions import UnsupportedWebhookEventType diff --git a/zerver/webhooks/gogs/view.py b/zerver/webhooks/gogs/view.py index 7fae8014d2..b6393c8e2c 100644 --- a/zerver/webhooks/gogs/view.py +++ b/zerver/webhooks/gogs/view.py @@ -1,8 +1,7 @@ # vim:fenc=utf-8 -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Protocol from django.http import HttpRequest, HttpResponse -from typing_extensions import Protocol from zerver.decorator import webhook_view from zerver.lib.exceptions import UnsupportedWebhookEventType diff --git a/zilencer/management/commands/rundjangoserver.py b/zilencer/management/commands/rundjangoserver.py index bac9171ce5..bf735c9ee7 100644 --- a/zilencer/management/commands/rundjangoserver.py +++ b/zilencer/management/commands/rundjangoserver.py @@ -1,7 +1,7 @@ from datetime import datetime +from typing import Protocol from django.core.management.commands.runserver import Command as DjangoCommand -from typing_extensions import Protocol class Writable(Protocol): diff --git a/zproject/backends.py b/zproject/backends.py index 6bf1e4d3a6..abb4b130f5 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -16,7 +16,20 @@ import binascii import json import logging from abc import ABC, abstractmethod -from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar, Union, cast +from typing import ( + Any, + Callable, + Dict, + List, + Optional, + Set, + Tuple, + Type, + TypedDict, + TypeVar, + Union, + cast, +) from urllib.parse import urlencode import magic @@ -55,7 +68,6 @@ from social_core.exceptions import ( SocialAuthBaseException, ) from social_core.pipeline.partial import partial -from typing_extensions import TypedDict from zxcvbn import zxcvbn from zerver.actions.create_user import do_create_user, do_reactivate_user diff --git a/zproject/default_settings.py b/zproject/default_settings.py index 679b1a9921..36d206d496 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -1,5 +1,5 @@ import os -from typing import TYPE_CHECKING, Any, Dict, List, Optional +from typing import TYPE_CHECKING, Any, Dict, List, Optional, TypedDict from scripts.lib.zulip_tools import deport @@ -7,7 +7,6 @@ from .config import DEVELOPMENT, PRODUCTION, get_secret if TYPE_CHECKING: from django_auth_ldap.config import LDAPSearch - from typing_extensions import TypedDict from zerver.lib.types import SAMLIdPConfigDict