Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typed_endpoint: Make is_optional understand T | None.
Anders Kaseorga2fad74a28fe
diff --git a/zerver/lib/typed_endpoint.py b/zerver/lib/typed_endpoint.pyindex 2744c1da606..d69e321cb3a 100644--- a/zerver/lib/typed_endpoint.py+++ b/zerver/lib/typed_endpoint.py@@ -1,5 +1,6 @@import inspectimport json+import typesfrom dataclasses import dataclassfrom enum import Enum, autofrom functools import wraps@@ -169,7 +170,7 @@ def is_annotated(type_annotation: Type[object]) -> bool:def is_optional(type_annotation: Type[object]) -> bool:origin = get_origin(type_annotation)type_args = get_args(type_annotation)- return origin is Union and type(None) in type_args and len(type_args) == 2+ return origin in (Union, types.UnionType) and type(None) in type_args and len(type_args) == 2API_PARAM_CONFIG_USAGE_HINT = f"""