From 8e7f2239a59f7d6f59f8f33864f9f6842a8bd810 Mon Sep 17 00:00:00 2001 From: Yannik Sembritzki Date: Fri, 20 Jan 2023 11:14:27 +0800 Subject: [PATCH] Fix failure to unpack json to typing.* types (typing.* cannot be instantiated) --- httpnet/_core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpnet/_core.py b/httpnet/_core.py index b8fb2d0..ad25b29 100644 --- a/httpnet/_core.py +++ b/httpnet/_core.py @@ -72,13 +72,13 @@ def __new__(mcs, typename: str, bases, ns): def _from_json_value(value, type_): if type_ is type(None) and value is None: return None - if repr(type_).startswith('typing.Union['): + if repr(type_).startswith('typing.Union[') or repr(type_).startswith('typing.Optional['): for t in reversed(type_.__args__): try: return _from_json_value(value, t) except (AttributeError, TypeError): continue - if isinstance(type_, (type(Iterable), type(Sequence))): + if repr(type_).startswith('typing.Iterable[') or repr(type_).startswith('typing.Sequence['): return [_from_json_value(v, type_.__args__[0]) for v in value] if type_ is datetime and isinstance(value, str): return dateutil.parser.parse(value)