Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
integrations: Fix config_options type.
Anders Kaseorg74e94ae78c4d
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex d0eb1d54f67..8cb35cc46b2 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -1,6 +1,6 @@import osfrom dataclasses import dataclass, field-from typing import Any, 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 path@@ -10,7 +10,6 @@ from django.utils.module_loading import import_stringfrom django.utils.translation import gettext as gettext_lazyfrom zerver.lib.storage import static_path-from zerver.lib.types import Validator"""This module declares all of the (documented) integrations availablein the Zulip server. The Integration class is used as part of@@ -31,6 +30,8 @@ Over time, we expect this registry to grow additional conveniencefeatures 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 = nameself.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.pyindex 49b25ce5396..df90aa42e53 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[sfor 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.pyindex f6be2329bd4..bf0f2628d61 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