mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
typing: Import StrPromise alias from django_stubs_ext.
This saves us from using a conditional import. Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
committed by
Tim Abbott
parent
df18bbbd48
commit
a4eaa770f0
@@ -1,5 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set
|
from typing import Any, Dict, Iterable, List, Optional, Set
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
@@ -8,6 +8,7 @@ from django.utils.timezone import now as timezone_now
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
from django.utils.translation import override as override_language
|
from django.utils.translation import override as override_language
|
||||||
|
from django_stubs_ext import StrPromise
|
||||||
|
|
||||||
from zerver.actions.message_delete import DeleteMessagesEvent
|
from zerver.actions.message_delete import DeleteMessagesEvent
|
||||||
from zerver.actions.message_flags import do_update_mobile_push_notification
|
from 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
|
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]:
|
def subscriber_info(user_id: int) -> Dict[str, Any]:
|
||||||
return {"id": user_id, "flags": ["read"]}
|
return {"id": user_id, "flags": ["read"]}
|
||||||
@@ -200,10 +198,10 @@ def send_message_moved_breadcrumbs(
|
|||||||
user_profile: UserProfile,
|
user_profile: UserProfile,
|
||||||
old_stream: Stream,
|
old_stream: Stream,
|
||||||
old_topic: str,
|
old_topic: str,
|
||||||
old_thread_notification_string: Optional["StrPromise"],
|
old_thread_notification_string: Optional[StrPromise],
|
||||||
new_stream: Stream,
|
new_stream: Stream,
|
||||||
new_topic: Optional[str],
|
new_topic: Optional[str],
|
||||||
new_thread_notification_string: Optional["StrPromise"],
|
new_thread_notification_string: Optional[StrPromise],
|
||||||
changed_messages_count: int,
|
changed_messages_count: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
# Since moving content between streams is highly disruptive,
|
# Since moving content between streams is highly disruptive,
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
This module stores data for "external account" custom profile field.
|
This module stores data for "external account" custom profile field.
|
||||||
"""
|
"""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Dict
|
from typing import Dict
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
|
from django_stubs_ext import StrPromise
|
||||||
|
|
||||||
from zerver.lib.types import ProfileFieldData
|
from zerver.lib.types import ProfileFieldData
|
||||||
from zerver.lib.validator import (
|
from zerver.lib.validator import (
|
||||||
@@ -15,8 +16,6 @@ from zerver.lib.validator import (
|
|||||||
check_required_string,
|
check_required_string,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from django.utils.functional import _StrPromise as StrPromise
|
|
||||||
|
|
||||||
# Default external account fields are by default available
|
# Default external account fields are by default available
|
||||||
# to realm admins, where realm admin only need to select
|
# to realm admins, where realm admin only need to select
|
||||||
@@ -25,7 +24,7 @@ if TYPE_CHECKING:
|
|||||||
@dataclass
|
@dataclass
|
||||||
class ExternalAccount:
|
class ExternalAccount:
|
||||||
text: str # Field text for admins - custom profile field in org settings view
|
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 view
|
||||||
hint: str # Field hint for realm users
|
hint: str # Field hint for realm users
|
||||||
url_pattern: str # Field URL linkifier
|
url_pattern: str # Field URL linkifier
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
# See https://zulip.readthedocs.io/en/latest/subsystems/hotspots.html
|
# See https://zulip.readthedocs.io/en/latest/subsystems/hotspots.html
|
||||||
# for documentation on this subsystem.
|
# for documentation on this subsystem.
|
||||||
from typing import TYPE_CHECKING, Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
|
from django_stubs_ext import StrPromise
|
||||||
|
|
||||||
from zerver.models import UserHotspot, UserProfile
|
from zerver.models import UserHotspot, UserProfile
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
INTRO_HOTSPOTS: Dict[str, Dict[str, StrPromise]] = {
|
||||||
from django.utils.functional import _StrPromise as StrPromise
|
|
||||||
|
|
||||||
INTRO_HOTSPOTS: Dict[str, Dict[str, "StrPromise"]] = {
|
|
||||||
"intro_streams": {
|
"intro_streams": {
|
||||||
"title": gettext_lazy("Catch up on a stream"),
|
"title": gettext_lazy("Catch up on a stream"),
|
||||||
"description": gettext_lazy(
|
"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
|
# 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
|
# a part of the initial tutorial. To that end, classifying them into
|
||||||
# categories which are aggregated in ALL_HOTSPOTS, seems like a good start.
|
# 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,
|
**INTRO_HOTSPOTS,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
from dataclasses import dataclass, field
|
from 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, Tuple
|
||||||
|
|
||||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||||
from django.urls import URLResolver, path
|
from django.urls import URLResolver, path
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
|
from django_stubs_ext import StrPromise
|
||||||
|
|
||||||
from zerver.lib.storage import static_path
|
from 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 available
|
"""This module declares all of the (documented) integrations available
|
||||||
in the Zulip server. The Integration class is used as part of
|
in the Zulip server. The Integration class is used as part of
|
||||||
generating the documentation on the /integrations page, while the
|
generating 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]]
|
OptionValidator = Callable[[str, str], Optional[str]]
|
||||||
|
|
||||||
META_CATEGORY: Dict[str, "StrPromise"] = {
|
META_CATEGORY: Dict[str, StrPromise] = {
|
||||||
"meta-integration": gettext_lazy("Integration frameworks"),
|
"meta-integration": gettext_lazy("Integration frameworks"),
|
||||||
"bots": gettext_lazy("Interactive bots"),
|
"bots": gettext_lazy("Interactive bots"),
|
||||||
}
|
}
|
||||||
|
|
||||||
CATEGORIES: Dict[str, "StrPromise"] = {
|
CATEGORIES: Dict[str, StrPromise] = {
|
||||||
**META_CATEGORY,
|
**META_CATEGORY,
|
||||||
"continuous-integration": gettext_lazy("Continuous integration"),
|
"continuous-integration": gettext_lazy("Continuous integration"),
|
||||||
"customer-support": gettext_lazy("Customer support"),
|
"customer-support": gettext_lazy("Customer support"),
|
||||||
|
|||||||
@@ -1,23 +1,10 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import (
|
from typing import Any, Callable, Dict, List, Optional, Tuple, TypedDict, TypeVar, Union
|
||||||
TYPE_CHECKING,
|
|
||||||
Any,
|
|
||||||
Callable,
|
|
||||||
Dict,
|
|
||||||
List,
|
|
||||||
Optional,
|
|
||||||
Tuple,
|
|
||||||
TypedDict,
|
|
||||||
TypeVar,
|
|
||||||
Union,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
from django_stubs_ext import StrPromise
|
||||||
from typing_extensions import NotRequired
|
from 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,
|
# See zerver/lib/validator.py for more details of Validators,
|
||||||
# including many examples
|
# including many examples
|
||||||
ResultT = TypeVar("ResultT")
|
ResultT = TypeVar("ResultT")
|
||||||
@@ -51,11 +38,9 @@ class ProfileDataElementUpdateDict(TypedDict):
|
|||||||
|
|
||||||
ProfileData = List[ProfileDataElement]
|
ProfileData = List[ProfileDataElement]
|
||||||
|
|
||||||
FieldElement = Tuple[
|
FieldElement = Tuple[int, StrPromise, Validator[ProfileDataElementValue], Callable[[Any], Any], str]
|
||||||
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]
|
||||||
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]]
|
ProfileFieldData = Dict[str, Union[Dict[str, str], str]]
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ from django.utils.timezone import now as timezone_now
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
from django_cte import CTEManager
|
from django_cte import CTEManager
|
||||||
|
from django_stubs_ext import StrPromise
|
||||||
|
|
||||||
from confirmation import settings as confirmation_settings
|
from confirmation import settings as confirmation_settings
|
||||||
from zerver.lib import cache
|
from zerver.lib import cache
|
||||||
@@ -119,7 +120,6 @@ if TYPE_CHECKING:
|
|||||||
# We use ModelBackend only for typing. Importing it otherwise causes circular dependency.
|
# We use ModelBackend only for typing. Importing it otherwise causes circular dependency.
|
||||||
from django.contrib.auth.backends import ModelBackend
|
from django.contrib.auth.backends import ModelBackend
|
||||||
from django.db.models.query import _QuerySet as ValuesQuerySet
|
from django.db.models.query import _QuerySet as ValuesQuerySet
|
||||||
from django.utils.functional import _StrPromise as StrPromise
|
|
||||||
|
|
||||||
|
|
||||||
class EmojiInfo(TypedDict):
|
class EmojiInfo(TypedDict):
|
||||||
@@ -2475,7 +2475,7 @@ class Stream(models.Model):
|
|||||||
|
|
||||||
# Who in the organization has permission to send messages to this stream.
|
# Who in the organization has permission to send messages to this stream.
|
||||||
stream_post_policy = models.PositiveSmallIntegerField(default=STREAM_POST_POLICY_EVERYONE)
|
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
|
# These strings should match the strings in the
|
||||||
# stream_post_policy_values object in stream_data.js.
|
# stream_post_policy_values object in stream_data.js.
|
||||||
STREAM_POST_POLICY_EVERYONE: gettext_lazy("All stream members can post"),
|
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]] = {
|
FIELD_CONVERTERS: Dict[int, Callable[[Any], Any]] = {
|
||||||
item[0]: item[3] for item in ALL_FIELD_TYPES
|
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
|
(item[0], item[1]) for item in ALL_FIELD_TYPES
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user