Skip to content

armgit / zulip

Public Imported from GitHub
0

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.py
index 2744c1da606..d69e321cb3a 100644
--- a/zerver/lib/typed_endpoint.py
+++ b/zerver/lib/typed_endpoint.py
@@ -1,5 +1,6 @@
import inspect
import json
+import types
from dataclasses import dataclass
from enum import Enum, auto
from 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) == 2
API_PARAM_CONFIG_USAGE_HINT = f"""