add support of Optional[Union[T]]

This commit is contained in:
Kirill A. Golubev
2021-08-02 14:46:05 +03:00
committed by GitHub
parent 43d2789636
commit 9a624437f4

View File

@@ -26,7 +26,7 @@ def _handle_optional(type_):
""" """
if typing.get_origin(type_) is typing.Union: if typing.get_origin(type_) is typing.Union:
args = typing.get_args(type_) args = typing.get_args(type_)
if len(args) == 2 and type(None) in args: if len(args) >= 2 and type(None) in args:
return next(iter(set(args) - {type(None)})) return next(iter(set(args) - {type(None)}))
return None return None