Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing: Import StrPromise alias from django_stubs_ext.
Zixuan James Lia4eaa770f059
diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.pyindex 403c7a0e094..f09bae74d7c 100644--- a/zerver/actions/message_edit.py+++ b/zerver/actions/message_edit.py@@ -1,5 +1,5 @@import datetime-from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set+from typing import Any, Dict, Iterable, List, Optional, Setfrom django.conf import settingsfrom django.db import transaction@@ -8,6 +8,7 @@ from django.utils.timezone import now as timezone_nowfrom django.utils.translation import gettext as _from django.utils.translation import gettext_lazyfrom django.utils.translation import override as override_language+from django_stubs_ext import StrPromisefrom zerver.actions.message_delete import DeleteMessagesEventfrom zerver.actions.message_flags import do_update_mobile_push_notification@@ -65,9 +66,6 @@ from zerver.models import ()from zerver.tornado.django_api import send_event-if TYPE_CHECKING:- from django.utils.functional import _StrPromise as StrPromise-def subscriber_info(user_id: int) -> Dict[str, Any]:return {"id": user_id, "flags": ["read"]}@@ -200,10 +198,10 @@ def send_message_moved_breadcrumbs(user_profile: UserProfile,old_stream: Stream,old_topic: str,- old_thread_notification_string: Optional["StrPromise"],+ old_thread_notification_string: Optional[StrPromise],new_stream: Stream,new_topic: Optional[str],- new_thread_notification_string: Optional["StrPromise"],+ new_thread_notification_string: Optional[StrPromise],changed_messages_count: int,) -> None:# Since moving content between streams is highly disruptive,diff --git a/zerver/lib/external_accounts.py b/zerver/lib/external_accounts.pyindex 13e3c7398fa..94f25bc8317 100644--- a/zerver/lib/external_accounts.py+++ b/zerver/lib/external_accounts.py@@ -2,11 +2,12 @@This module stores data for "external account" custom profile field."""from dataclasses import dataclass-from typing import TYPE_CHECKING, Dict+from typing import Dictfrom django.core.exceptions import ValidationErrorfrom django.utils.translation import gettext as _from django.utils.translation import gettext_lazy+from django_stubs_ext import StrPromisefrom zerver.lib.types import ProfileFieldDatafrom zerver.lib.validator import (@@ -15,8 +16,6 @@ from zerver.lib.validator import (check_required_string,)-if TYPE_CHECKING:- from django.utils.functional import _StrPromise as StrPromise# Default external account fields are by default available# to realm admins, where realm admin only need to select@@ -25,7 +24,7 @@ if TYPE_CHECKING:@dataclassclass ExternalAccount:text: str # Field text for admins - custom profile field in org settings view- name: "StrPromise" # Field label or name - user profile in user settings view+ name: StrPromise # Field label or name - user profile in user settings viewhint: str # Field hint for realm usersurl_pattern: str # Field URL linkifierdiff --git a/zerver/lib/hotspots.py b/zerver/lib/hotspots.pyindex b6c22117466..c1131f874ea 100644--- a/zerver/lib/hotspots.py+++ b/zerver/lib/hotspots.py@@ -1,16 +1,14 @@# See https://zulip.readthedocs.io/en/latest/subsystems/hotspots.html# for documentation on this subsystem.-from typing import TYPE_CHECKING, Dict, List+from typing import Dict, Listfrom django.conf import settingsfrom django.utils.translation import gettext_lazy+from django_stubs_ext import StrPromisefrom zerver.models import UserHotspot, UserProfile-if TYPE_CHECKING:- from django.utils.functional import _StrPromise as StrPromise--INTRO_HOTSPOTS: Dict[str, Dict[str, "StrPromise"]] = {+INTRO_HOTSPOTS: Dict[str, Dict[str, StrPromise]] = {"intro_streams": {"title": gettext_lazy("Catch up on a stream"),"description": gettext_lazy(@@ -44,7 +42,7 @@ INTRO_HOTSPOTS: Dict[str, Dict[str, "StrPromise"]] = {# We would most likely implement new hotspots in the future that aren't# a part of the initial tutorial. To that end, classifying them into# categories which are aggregated in ALL_HOTSPOTS, seems like a good start.-ALL_HOTSPOTS: Dict[str, Dict[str, "StrPromise"]] = {+ALL_HOTSPOTS: Dict[str, Dict[str, StrPromise]] = {**INTRO_HOTSPOTS,}diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex ef692833ade..1ff026f20e0 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -1,17 +1,15 @@import osfrom dataclasses import dataclass, field-from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Sequence, Tuple+from typing import Any, Callable, Dict, List, Optional, Sequence, Tuplefrom django.contrib.staticfiles.storage import staticfiles_storagefrom django.urls import URLResolver, pathfrom django.utils.module_loading import import_stringfrom django.utils.translation import gettext_lazy+from django_stubs_ext import StrPromisefrom zerver.lib.storage import static_path-if TYPE_CHECKING:- from django.utils.functional import _StrPromise as StrPromise-"""This module declares all of the (documented) integrations availablein the Zulip server. The Integration class is used as part ofgenerating the documentation on the /integrations page, while the@@ -35,12 +33,12 @@ features for writing and configuring integrations efficiently.OptionValidator = Callable[[str, str], Optional[str]]-META_CATEGORY: Dict[str, "StrPromise"] = {+META_CATEGORY: Dict[str, StrPromise] = {"meta-integration": gettext_lazy("Integration frameworks"),"bots": gettext_lazy("Interactive bots"),}-CATEGORIES: Dict[str, "StrPromise"] = {+CATEGORIES: Dict[str, StrPromise] = {**META_CATEGORY,"continuous-integration": gettext_lazy("Continuous integration"),"customer-support": gettext_lazy("Customer support"),diff --git a/zerver/lib/types.py b/zerver/lib/types.pyindex 69292e2f2e6..22c1e2a17de 100644--- a/zerver/lib/types.py+++ b/zerver/lib/types.py@@ -1,23 +1,10 @@import datetimefrom dataclasses import dataclass-from typing import (- TYPE_CHECKING,- Any,- Callable,- Dict,- List,- Optional,- Tuple,- TypedDict,- TypeVar,- Union,-)+from typing import Any, Callable, Dict, List, Optional, Tuple, TypedDict, TypeVar, Union+from django_stubs_ext import StrPromisefrom typing_extensions import NotRequired-if TYPE_CHECKING:- from django.utils.functional import _StrPromise as StrPromise-# See zerver/lib/validator.py for more details of Validators,# including many examplesResultT = TypeVar("ResultT")@@ -51,11 +38,9 @@ class ProfileDataElementUpdateDict(TypedDict):ProfileData = List[ProfileDataElement]-FieldElement = Tuple[- int, "StrPromise", Validator[ProfileDataElementValue], Callable[[Any], Any], str-]-ExtendedFieldElement = Tuple[int, "StrPromise", ExtendedValidator, Callable[[Any], Any], str]-UserFieldElement = Tuple[int, "StrPromise", RealmUserValidator, Callable[[Any], Any], str]+FieldElement = Tuple[int, StrPromise, Validator[ProfileDataElementValue], Callable[[Any], Any], str]+ExtendedFieldElement = Tuple[int, StrPromise, ExtendedValidator, Callable[[Any], Any], str]+UserFieldElement = Tuple[int, StrPromise, RealmUserValidator, Callable[[Any], Any], str]ProfileFieldData = Dict[str, Union[Dict[str, str], str]]diff --git a/zerver/models.py b/zerver/models.pyindex 5f08c6ad3db..abee25c47f7 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -50,6 +50,7 @@ from django.utils.timezone import now as timezone_nowfrom django.utils.translation import gettext as _from django.utils.translation import gettext_lazyfrom django_cte import CTEManager+from django_stubs_ext import StrPromisefrom confirmation import settings as confirmation_settingsfrom zerver.lib import cache@@ -119,7 +120,6 @@ if TYPE_CHECKING:# We use ModelBackend only for typing. Importing it otherwise causes circular dependency.from django.contrib.auth.backends import ModelBackendfrom django.db.models.query import _QuerySet as ValuesQuerySet- from django.utils.functional import _StrPromise as StrPromiseclass EmojiInfo(TypedDict):@@ -2475,7 +2475,7 @@ class Stream(models.Model):# Who in the organization has permission to send messages to this stream.stream_post_policy = models.PositiveSmallIntegerField(default=STREAM_POST_POLICY_EVERYONE)- POST_POLICIES: Dict[int, "StrPromise"] = {+ POST_POLICIES: Dict[int, StrPromise] = {# These strings should match the strings in the# stream_post_policy_values object in stream_data.js.STREAM_POST_POLICY_EVERYONE: gettext_lazy("All stream members can post"),@@ -4564,7 +4564,7 @@ class CustomProfileField(models.Model):FIELD_CONVERTERS: Dict[int, Callable[[Any], Any]] = {item[0]: item[3] for item in ALL_FIELD_TYPES}- FIELD_TYPE_CHOICES: List[Tuple[int, "StrPromise"]] = [+ FIELD_TYPE_CHOICES: List[Tuple[int, StrPromise]] = [(item[0], item[1]) for item in ALL_FIELD_TYPES]