@@ -170,13 +170,6 @@ def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]],
170170 return None
171171
172172
173- try :
174- basestring # type: ignore
175- unicode_str = unicode # type: ignore
176- except NameError :
177- basestring = str
178- unicode_str = str
179-
180173_LOGGER = logging .getLogger (__name__ )
181174
182175try :
@@ -545,7 +538,7 @@ class Serializer(object):
545538 "multiple" : lambda x , y : x % y != 0 ,
546539 }
547540
548- def __init__ (self , classes : Optional [Mapping [str , Type [ ModelType ] ]] = None ):
541+ def __init__ (self , classes : Optional [Mapping [str , type ]] = None ):
549542 self .serialize_type = {
550543 "iso-8601" : Serializer .serialize_iso ,
551544 "rfc-1123" : Serializer .serialize_rfc ,
@@ -561,7 +554,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
561554 "[]" : self .serialize_iter ,
562555 "{}" : self .serialize_dict ,
563556 }
564- self .dependencies : Dict [str , Type [ ModelType ] ] = dict (classes ) if classes else {}
557+ self .dependencies : Dict [str , type ] = dict (classes ) if classes else {}
565558 self .key_transformer = full_restapi_key_transformer
566559 self .client_side_validation = True
567560
@@ -649,7 +642,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
649642 else : # That's a basic type
650643 # Integrate namespace if necessary
651644 local_node = _create_xml_node (xml_name , xml_prefix , xml_ns )
652- local_node .text = unicode_str (new_attr )
645+ local_node .text = str (new_attr )
653646 serialized .append (local_node ) # type: ignore
654647 else : # JSON
655648 for k in reversed (keys ): # type: ignore
@@ -994,7 +987,7 @@ def serialize_object(self, attr, **kwargs):
994987 return self .serialize_basic (attr , self .basic_types [obj_type ], ** kwargs )
995988 if obj_type is _long_type :
996989 return self .serialize_long (attr )
997- if obj_type is unicode_str :
990+ if obj_type is str :
998991 return self .serialize_unicode (attr )
999992 if obj_type is datetime .datetime :
1000993 return self .serialize_iso (attr )
@@ -1370,7 +1363,7 @@ class Deserializer(object):
13701363
13711364 valid_date = re .compile (r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}" r"\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?" )
13721365
1373- def __init__ (self , classes : Optional [Mapping [str , Type [ ModelType ] ]] = None ):
1366+ def __init__ (self , classes : Optional [Mapping [str , type ]] = None ):
13741367 self .deserialize_type = {
13751368 "iso-8601" : Deserializer .deserialize_iso ,
13761369 "rfc-1123" : Deserializer .deserialize_rfc ,
@@ -1390,7 +1383,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
13901383 "duration" : (isodate .Duration , datetime .timedelta ),
13911384 "iso-8601" : (datetime .datetime ),
13921385 }
1393- self .dependencies : Dict [str , Type [ ModelType ] ] = dict (classes ) if classes else {}
1386+ self .dependencies : Dict [str , type ] = dict (classes ) if classes else {}
13941387 self .key_extractors = [rest_key_extractor , xml_key_extractor ]
13951388 # Additional properties only works if the "rest_key_extractor" is used to
13961389 # extract the keys. Making it to work whatever the key extractor is too much
@@ -1443,7 +1436,7 @@ def _deserialize(self, target_obj, data):
14431436
14441437 response , class_name = self ._classify_target (target_obj , data )
14451438
1446- if isinstance (response , basestring ):
1439+ if isinstance (response , str ):
14471440 return self .deserialize_data (data , response )
14481441 elif isinstance (response , type ) and issubclass (response , Enum ):
14491442 return self .deserialize_enum (data , response )
@@ -1514,14 +1507,14 @@ def _classify_target(self, target, data):
15141507 if target is None :
15151508 return None , None
15161509
1517- if isinstance (target , basestring ):
1510+ if isinstance (target , str ):
15181511 try :
15191512 target = self .dependencies [target ]
15201513 except KeyError :
15211514 return target , target
15221515
15231516 try :
1524- target = target ._classify (data , self .dependencies )
1517+ target = target ._classify (data , self .dependencies ) # type: ignore
15251518 except AttributeError :
15261519 pass # Target is not a Model, no classify
15271520 return target , target .__class__ .__name__ # type: ignore
@@ -1577,7 +1570,7 @@ def _unpack_content(raw_data, content_type=None):
15771570 if hasattr (raw_data , "_content_consumed" ):
15781571 return RawDeserializer .deserialize_from_http_generics (raw_data .text , raw_data .headers )
15791572
1580- if isinstance (raw_data , (basestring , bytes )) or hasattr (raw_data , "read" ):
1573+ if isinstance (raw_data , (str , bytes )) or hasattr (raw_data , "read" ):
15811574 return RawDeserializer .deserialize_from_text (raw_data , content_type ) # type: ignore
15821575 return raw_data
15831576
@@ -1699,7 +1692,7 @@ def deserialize_object(self, attr, **kwargs):
16991692 if isinstance (attr , ET .Element ):
17001693 # Do no recurse on XML, just return the tree as-is
17011694 return attr
1702- if isinstance (attr , basestring ):
1695+ if isinstance (attr , str ):
17031696 return self .deserialize_basic (attr , "str" )
17041697 obj_type = type (attr )
17051698 if obj_type in self .basic_types :
@@ -1756,7 +1749,7 @@ def deserialize_basic(self, attr, data_type):
17561749 if data_type == "bool" :
17571750 if attr in [True , False , 1 , 0 ]:
17581751 return bool (attr )
1759- elif isinstance (attr , basestring ):
1752+ elif isinstance (attr , str ):
17601753 if attr .lower () in ["true" , "1" ]:
17611754 return True
17621755 elif attr .lower () in ["false" , "0" ]:
0 commit comments