1
+ import sys
1
2
import typing
2
3
from typing import Any , Dict , List , Mapping , Set
3
4
@@ -14,7 +15,7 @@ def recast_object(
14
15
if not isinstance (json_data , dict ):
15
16
raise InvalidRequest (f"Can only parse dict items, not { type (json_data )} " )
16
17
# if type is Any, we leave it as is
17
- if cls == typing .Any :
18
+ if cls is typing .Any :
18
19
return
19
20
for k , v in json_data .items ():
20
21
if isinstance (v , dict ):
@@ -35,7 +36,7 @@ def recast_object(
35
36
36
37
def _recast_lists (cls : Any , k : str , v : List [Any ], classes : Dict [str , Any ]) -> List [Any ]:
37
38
# Leave as is if type is Any
38
- if cls == typing .Any :
39
+ if cls is typing .Any :
39
40
return v
40
41
if "__dataclass_fields__" not in dir (cls ):
41
42
pass
@@ -64,7 +65,7 @@ def cast_sequence_item(cls: Any, k: str, item: Any, classes: Dict[str, Any]) ->
64
65
65
66
66
67
def _recast_primitive (cls : Any , k : str , v : Any ) -> Any :
67
- if cls == typing .Any :
68
+ if cls is typing .Any :
68
69
# If the type is Any, we cannot guess what the original type was, so we leave
69
70
# it as a string
70
71
return v
@@ -126,6 +127,6 @@ def get_forward_ref_type() -> Any:
126
127
# ignoring mypy on the import as it catches (_)ForwardRef as invalid, use for
127
128
# introspection is valid:
128
129
# https://docs.python.org/3/library/typing.html#typing.ForwardRef
129
- if "ForwardRef" in dir ( typing ):
130
- return typing .ForwardRef # type: ignore
131
- return typing ._ForwardRef # type: ignore
130
+ if sys . version_info < ( 3 , 7 ):
131
+ return typing ._ForwardRef # type: ignore
132
+ return typing .ForwardRef
0 commit comments