mirror of
https://github.com/zulip/zulip.git
synced 2026-07-15 21:03:26 +08:00
typed_endpoint: Make is_optional understand T | None.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
f23fdede67
commit
a2fad74a28
@ -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"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user