1+ from __future__ import annotations
12import dataclasses
23import datetime
34import inspect
@@ -43,7 +44,7 @@ def convert_from_dict(cls: type, data: dict) -> object:
4344 if data is None :
4445 return data
4546
46- if type (data ) == cls :
47+ if isinstance (data , cls ) :
4748 return data
4849
4950 if dataclasses .is_dataclass (cls ):
@@ -53,7 +54,7 @@ def convert_from_dict(cls: type, data: dict) -> object:
5354 if not ((str (typ ).startswith ('dict[' ) or
5455 str (typ ).startswith ('typing.Dict[' ) or
5556 str (typ ).startswith ('requests.structures.CaseInsensitiveDict[' ) or
56- typ == dict or str (typ ).startswith ('OrderedDict[' ))):
57+ typ is dict or str (typ ).startswith ('OrderedDict[' ))):
5758 data = {}
5859
5960 members = inspect .signature (cls .__init__ ).parameters
@@ -71,17 +72,15 @@ def convert_from_dict(cls: type, data: dict) -> object:
7172 else :
7273 kwargs [member ] = members [member ].default
7374 elif str (typ ).startswith ('typing.List[' ) or str (typ ).startswith ('typing.Set[' ) or str (typ ).startswith ('list[' ):
74- values = []
7575 generic_type = object
7676 if len (generic_types ) > 0 :
7777 generic_type = generic_types [0 ]
78- for val in data [member ]:
79- values .append (get_value (generic_type , val ))
78+ values = [get_value (generic_type , item ) for item in data [member ]]
8079 kwargs [member ] = values
8180 elif (str (typ ).startswith ('dict[' ) or
8281 str (typ ).startswith ('typing.Dict[' ) or
8382 str (typ ).startswith ('requests.structures.CaseInsensitiveDict[' ) or
84- typ == dict or str (typ ).startswith ('OrderedDict[' )):
83+ typ is dict or str (typ ).startswith ('OrderedDict[' )):
8584
8685 values = {}
8786 generic_type = object
@@ -91,7 +90,7 @@ def convert_from_dict(cls: type, data: dict) -> object:
9190 v = data [member ][k ]
9291 values [k ] = get_value (generic_type , v )
9392 kwargs [member ] = values
94- elif typ == inspect .Parameter .empty :
93+ elif typ is inspect .Parameter .empty :
9594 if inspect .Parameter .VAR_KEYWORD == members [member ].kind :
9695 if type (data ) in dict_types :
9796 kwargs .update (data )
@@ -113,7 +112,7 @@ def get_value(typ: type, val: object) -> object:
113112 values = [get_value (type (item ), item ) for item in val ]
114113 return values
115114 elif str (typ ).startswith ('dict[' ) or str (typ ).startswith (
116- 'typing.Dict[' ) or str (typ ).startswith ('requests.structures.CaseInsensitiveDict[' ) or typ == dict :
115+ 'typing.Dict[' ) or str (typ ).startswith ('requests.structures.CaseInsensitiveDict[' ) or typ is dict :
117116 values = {}
118117 for k in val :
119118 v = val [k ]
0 commit comments