1+ import sys
12import typing
23from typing import Any , Dict , List , Mapping , Set
34
@@ -14,7 +15,7 @@ def recast_object(
1415 if not isinstance (json_data , dict ):
1516 raise InvalidRequest (f"Can only parse dict items, not { type (json_data )} " )
1617 # if type is Any, we leave it as is
17- if cls == typing .Any :
18+ if cls is typing .Any :
1819 return
1920 for k , v in json_data .items ():
2021 if isinstance (v , dict ):
@@ -35,7 +36,7 @@ def recast_object(
3536
3637def _recast_lists (cls : Any , k : str , v : List [Any ], classes : Dict [str , Any ]) -> List [Any ]:
3738 # Leave as is if type is Any
38- if cls == typing .Any :
39+ if cls is typing .Any :
3940 return v
4041 if "__dataclass_fields__" not in dir (cls ):
4142 pass
@@ -64,7 +65,7 @@ def cast_sequence_item(cls: Any, k: str, item: Any, classes: Dict[str, Any]) ->
6465
6566
6667def _recast_primitive (cls : Any , k : str , v : Any ) -> Any :
67- if cls == typing .Any :
68+ if cls is typing .Any :
6869 # If the type is Any, we cannot guess what the original type was, so we leave
6970 # it as a string
7071 return v
@@ -126,6 +127,6 @@ def get_forward_ref_type() -> Any:
126127 # ignoring mypy on the import as it catches (_)ForwardRef as invalid, use for
127128 # introspection is valid:
128129 # 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