Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
data_types: Generalize StringDictType.
Steve Howell6c74a4469707
diff --git a/tools/check-node-fixtures b/tools/check-node-fixturesindex 0ff6f312c09..27a4b68b6cc 100755--- a/tools/check-node-fixtures+++ b/tools/check-node-fixtures@@ -133,9 +133,7 @@ def from_openapi(node: Dict[str, Any]) -> Any:# this might be a glitch in our current spec? or# maybe I just understand it yetif isinstance(node["additionalProperties"], dict):- if node["additionalProperties"].get("type", "") == "string":- return StringDictType()- return from_openapi(node["additionalProperties"])+ return StringDictType(from_openapi(node["additionalProperties"]))if "properties" not in node:return dictdiff --git a/zerver/lib/data_types.py b/zerver/lib/data_types.pyindex 254db337918..951a1a1f9ee 100644--- a/zerver/lib/data_types.py+++ b/zerver/lib/data_types.py@@ -123,17 +123,21 @@ class ListType:@dataclassclass StringDictType:+ value_type: Any+def check_data(self, var_name: str, val: Dict[Any, Any]) -> None:if not isinstance(val, dict):raise AssertionError(f"{var_name} is not a dictionary")for key, value in val.items():- if isinstance(key, str) and isinstance(value, str):- continue- raise AssertionError(f"{var_name} is not a string:string dictionary")+ if not isinstance(key, str):+ raise AssertionError(f"{var_name} has a non-string key")++ check_data(self.value_type, f"{var_name}[{key}]", value)def schema(self, var_name: str) -> str:- return f"{var_name}: string_dict"+ sub_schema = schema("value", self.value_type)+ return f"{var_name} (string_dict):\n{indent(sub_schema)}"@dataclassdiff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.pyindex ecef2f9deea..c9e5c507725 100644--- a/zerver/lib/event_schema.py+++ b/zerver/lib/event_schema.py@@ -332,7 +332,7 @@ bot_services_outgoing_type = DictType(])-config_data_schema = StringDictType()+config_data_schema = StringDictType(str)bot_services_embedded_type = DictType(required_keys=[diff --git a/zerver/tests/test_data_types.py b/zerver/tests/test_data_types.pyindex b2a4e499c0f..045924a0df5 100644--- a/zerver/tests/test_data_types.py+++ b/zerver/tests/test_data_types.py@@ -30,14 +30,15 @@ class MiscTest(ZulipTestCase):("tup", TupleType([int, str])),("level", EnumType([1, 2, 3])),("lst", ListType(int)),- ("config", StringDictType()),+ ("config", StringDictType(str)),("value", UnionType([int, str])),("url", UrlType()),])expected = """test (dict):- config: string_dict+ config (string_dict):+ value: strflag: boollevel in [1, 2, 3]lst (list):