diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index d0eb1d54f6..8cb35cc46b 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -1,6 +1,6 @@ import os from dataclasses import dataclass, field -from typing import Any, 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.urls import path @@ -10,7 +10,6 @@ from django.utils.module_loading import import_string from django.utils.translation import gettext as gettext_lazy from zerver.lib.storage import static_path -from zerver.lib.types import Validator """This module declares all of the (documented) integrations available in the Zulip server. The Integration class is used as part of @@ -31,6 +30,8 @@ Over time, we expect this registry to grow additional convenience features for writing and configuring integrations efficiently. """ +OptionValidator = Callable[[str, str], Optional[str]] + CATEGORIES: Dict[str, Promise] = { "meta-integration": gettext_lazy("Integration frameworks"), "continuous-integration": gettext_lazy("Continuous integration"), @@ -66,7 +67,7 @@ class Integration: doc: Optional[str] = None, stream_name: Optional[str] = None, legacy: bool = False, - config_options: Sequence[Tuple[str, str, Validator[object]]] = [], + config_options: Sequence[Tuple[str, str, OptionValidator]] = [], ) -> None: self.name = name self.client_name = client_name @@ -188,7 +189,7 @@ class WebhookIntegration(Integration): doc: Optional[str] = None, stream_name: Optional[str] = None, legacy: bool = False, - config_options: Sequence[Tuple[str, str, Validator[object]]] = [], + config_options: Sequence[Tuple[str, str, OptionValidator]] = [], ) -> None: if client_name is None: client_name = self.DEFAULT_CLIENT_NAME.format(name=name.title()) diff --git a/zerver/lib/users.py b/zerver/lib/users.py index 49b25ce539..df90aa42e5 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -101,7 +101,7 @@ def check_valid_bot_config(bot_type: int, service_name: str, config_data: Dict[s for key, validator in config_options.items(): value = config_data[key] error = validator(key, value) - if error: + if error is not None: raise JsonableError(_("Invalid {} value {} ({})").format(key, value, error)) elif bot_type == UserProfile.EMBEDDED_BOT: diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.py index f6be2329bd..bf0f2628d6 100644 --- a/zerver/tests/test_bots.py +++ b/zerver/tests/test_bots.py @@ -29,8 +29,8 @@ from zerver.models import ( # A test validator -def _check_string(var_name: str, val: object) -> Optional[str]: - if str(val).startswith("_"): +def _check_string(var_name: str, val: str) -> Optional[str]: + if val.startswith("_"): return f'{var_name} starts with a "_" and is hence invalid.' return None