From 3bf8ee2156048271dc0ac3e05cbc62be64e30139 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sun, 26 Jun 2022 01:03:34 -0700 Subject: [PATCH] python: Unquote some unnecessarily quoted type annotations. Signed-off-by: Anders Kaseorg --- scripts/lib/upgrade-zulip-stage-2 | 7 ++----- tools/lib/provision.py | 7 ++----- zerver/lib/request.py | 2 +- zerver/lib/streams.py | 4 ++-- zerver/lib/topic.py | 6 +++--- zerver/lib/user_groups.py | 8 ++++---- zerver/lib/users.py | 2 +- zerver/lib/validator.py | 6 +++--- zerver/views/message_fetch.py | 16 ++++++++-------- 9 files changed, 26 insertions(+), 32 deletions(-) diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index 620621f36a..637fe94c8b 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -14,10 +14,7 @@ import shutil import subprocess import sys import time -from typing import TYPE_CHECKING, Optional - -if TYPE_CHECKING: - from typing import NoReturn +from typing import NoReturn, Optional os.environ["PYTHONUNBUFFERED"] = "y" @@ -47,7 +44,7 @@ logging.Formatter.converter = time.gmtime logging.basicConfig(format="%(asctime)s upgrade-zulip-stage-2: %(message)s", level=logging.INFO) -def error_desupported_os(vendor: str, os_version: str) -> "NoReturn": +def error_desupported_os(vendor: str, os_version: str) -> NoReturn: # Link to documentation for how to correctly upgrade the OS. logging.critical("Unsupported platform: %s %s", vendor, os_version) logging.info( diff --git a/tools/lib/provision.py b/tools/lib/provision.py index 93ab59d1a0..90d123510c 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -6,13 +6,13 @@ import os import platform import subprocess import sys +from typing import List, NoReturn os.environ["PYTHONUNBUFFERED"] = "y" ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(ZULIP_PATH) -from typing import TYPE_CHECKING, List from scripts.lib.node_cache import NODE_MODULES_CACHE_PATH, setup_node_modules from scripts.lib.setup_venv import get_venv_dependencies @@ -27,9 +27,6 @@ from scripts.lib.zulip_tools import ( ) from tools.setup import setup_venvs -if TYPE_CHECKING: - from typing import NoReturn - VAR_DIR_PATH = os.path.join(ZULIP_PATH, "var") CONTINUOUS_INTEGRATION = "GITHUB_ACTIONS" in os.environ @@ -350,7 +347,7 @@ def install_yum_deps(deps_to_install: List[str]) -> None: ) -def main(options: argparse.Namespace) -> "NoReturn": +def main(options: argparse.Namespace) -> NoReturn: # yarn and management commands expect to be run from the root of the # project. diff --git a/zerver/lib/request.py b/zerver/lib/request.py index b7d0a18b9a..290cd8799e 100644 --- a/zerver/lib/request.py +++ b/zerver/lib/request.py @@ -58,7 +58,7 @@ class RequestNotes(BaseNotes[HttpRequest, "RequestNotes"]): realm: Optional[Realm] = None has_fetched_realm: bool = False set_language: Optional[str] = None - ratelimits_applied: List["rate_limiter.RateLimitResult"] = field(default_factory=lambda: []) + ratelimits_applied: List[rate_limiter.RateLimitResult] = field(default_factory=lambda: []) query: Optional[str] = None error_format: Optional[str] = None placeholder_open_graph_description: Optional[str] = None diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index f98044857b..7e39892227 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -411,11 +411,11 @@ def access_stream_by_id( return (stream, sub) -def get_public_streams_queryset(realm: Realm) -> "QuerySet[Stream]": +def get_public_streams_queryset(realm: Realm) -> QuerySet[Stream]: return Stream.objects.filter(realm=realm, invite_only=False, history_public_to_subscribers=True) -def get_web_public_streams_queryset(realm: Realm) -> "QuerySet[Stream]": +def get_web_public_streams_queryset(realm: Realm) -> QuerySet[Stream]: # This should match the include_web_public code path in do_get_streams. return Stream.objects.filter( realm=realm, diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py index 2dd145b157..d027307bab 100644 --- a/zerver/lib/topic.py +++ b/zerver/lib/topic.py @@ -70,19 +70,19 @@ DB_TOPIC_NAME = "subject" MESSAGE__TOPIC = "message__subject" -def topic_match_sa(topic_name: str) -> "ColumnElement[Boolean]": +def topic_match_sa(topic_name: str) -> ColumnElement[Boolean]: # _sa is short for SQLAlchemy, which we use mostly for # queries that search messages topic_cond = func.upper(column("subject", Text)) == func.upper(literal(topic_name)) return topic_cond -def get_resolved_topic_condition_sa() -> "ColumnElement[Boolean]": +def get_resolved_topic_condition_sa() -> ColumnElement[Boolean]: resolved_topic_cond = column("subject", Text).startswith(RESOLVED_TOPIC_PREFIX) return resolved_topic_cond -def topic_column_sa() -> "ColumnElement[Text]": +def topic_column_sa() -> ColumnElement[Text]: return column("subject", Text) diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.py index 7bd2dafdf2..d4ee6a3a44 100644 --- a/zerver/lib/user_groups.py +++ b/zerver/lib/user_groups.py @@ -120,7 +120,7 @@ def get_user_group_direct_member_ids(user_group: UserGroup) -> List[int]: ) -def get_user_group_direct_members(user_group: UserGroup) -> "QuerySet[UserGroup]": +def get_user_group_direct_members(user_group: UserGroup) -> QuerySet[UserGroup]: return user_group.direct_members.all() @@ -141,7 +141,7 @@ def get_direct_memberships_of_users(user_group: UserGroup, members: List[UserPro # https://code.djangoproject.com/ticket/28919 -def get_recursive_subgroups(user_group: UserGroup) -> "QuerySet[UserGroup]": +def get_recursive_subgroups(user_group: UserGroup) -> QuerySet[UserGroup]: cte = With.recursive( lambda cte: UserGroup.objects.filter(id=user_group.id) .values("id") @@ -150,11 +150,11 @@ def get_recursive_subgroups(user_group: UserGroup) -> "QuerySet[UserGroup]": return cte.join(UserGroup, id=cte.col.id).with_cte(cte) -def get_recursive_group_members(user_group: UserGroup) -> "QuerySet[UserProfile]": +def get_recursive_group_members(user_group: UserGroup) -> QuerySet[UserProfile]: return UserProfile.objects.filter(direct_groups__in=get_recursive_subgroups(user_group)) -def get_recursive_membership_groups(user_profile: UserProfile) -> "QuerySet[UserGroup]": +def get_recursive_membership_groups(user_profile: UserProfile) -> QuerySet[UserGroup]: cte = With.recursive( lambda cte: user_profile.direct_groups.values("id").union( cte.join(UserGroup, direct_subgroups=cte.col.id).values("id") diff --git a/zerver/lib/users.py b/zerver/lib/users.py index df90aa42e5..bf14923d82 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -164,7 +164,7 @@ def is_administrator_role(role: int) -> bool: def bulk_get_users( - emails: List[str], realm: Optional[Realm], base_query: "QuerySet[UserProfile]" = None + emails: List[str], realm: Optional[Realm], base_query: QuerySet[UserProfile] = None ) -> Dict[str, UserProfile]: if base_query is None: assert realm is not None diff --git a/zerver/lib/validator.py b/zerver/lib/validator.py index e50b33219f..94d2cff5b9 100644 --- a/zerver/lib/validator.py +++ b/zerver/lib/validator.py @@ -696,7 +696,7 @@ class WildValueDict(WildValue): return wrap_wild_value(var_name, item) - def get(self, key: str, default: object = None) -> "WildValue": + def get(self, key: str, default: object = None) -> WildValue: item = self.value.get(key, default) if isinstance(item, WildValue): return item @@ -705,11 +705,11 @@ class WildValueDict(WildValue): def keys(self) -> Iterator[str]: yield from self.value.keys() - def values(self) -> Iterator["WildValue"]: + def values(self) -> Iterator[WildValue]: for key, value in self.value.items(): yield wrap_wild_value(f"{self.var_name}[{key!r}]", value) - def items(self) -> Iterator[Tuple[str, "WildValue"]]: + def items(self) -> Iterator[Tuple[str, WildValue]]: for key, value in self.value.items(): yield key, wrap_wild_value(f"{self.var_name}[{key!r}]", value) diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.py index 3280e09b89..08e64cecd2 100644 --- a/zerver/views/message_fetch.py +++ b/zerver/views/message_fetch.py @@ -105,10 +105,10 @@ TS_STOP = "" def ts_locs_array( - config: "ColumnElement[Text]", - text: "ColumnElement[Text]", - tsquery: "ColumnElement[Any]", -) -> "ColumnElement[ARRAY[Integer]]": + config: ColumnElement[Text], + text: ColumnElement[Text], + tsquery: ColumnElement[Any], +) -> ColumnElement[ARRAY[Integer]]: options = f"HighlightAll = TRUE, StartSel = {TS_START}, StopSel = {TS_STOP}" delimited = func.ts_headline(config, text, tsquery, options, type_=Text) part = func.unnest( @@ -149,7 +149,7 @@ class NarrowBuilder: def __init__( self, user_profile: Optional[UserProfile], - msg_id_column: "ColumnElement[Integer]", + msg_id_column: ColumnElement[Integer], realm: Realm, is_web_public_query: bool = False, ) -> None: @@ -771,7 +771,7 @@ def exclude_muting_conditions( def get_base_query_for_search( user_profile: Optional[UserProfile], need_message: bool, need_user_message: bool -) -> Tuple[Select, "ColumnElement[Integer]"]: +) -> Tuple[Select, ColumnElement[Integer]]: # Handle the simple case where user_message isn't involved first. if not need_user_message: assert need_message @@ -809,7 +809,7 @@ def get_base_query_for_search( def add_narrow_conditions( user_profile: Optional[UserProfile], - inner_msg_id_col: "ColumnElement[Integer]", + inner_msg_id_col: ColumnElement[Integer], query: Select, narrow: OptionalNarrowListT, is_web_public_query: bool, @@ -1181,7 +1181,7 @@ def limit_query_to_range( anchor: int, anchored_to_left: bool, anchored_to_right: bool, - id_col: "ColumnElement[Integer]", + id_col: ColumnElement[Integer], first_visible_message_id: int, ) -> SelectBase: """