@@ -346,7 +346,7 @@ def _get_model(module_name: str, model_name: str):
346346
347347
348348class _MyMutableMapping (MutableMapping [str , typing .Any ]):
349- def __init__ (self , data : typing . Dict [str , typing .Any ]) -> None :
349+ def __init__ (self , data : dict [str , typing .Any ]) -> None :
350350 self ._data = data
351351
352352 def __contains__ (self , key : typing .Any ) -> bool :
@@ -426,7 +426,7 @@ def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
426426 return self ._data .pop (key )
427427 return self ._data .pop (key , default )
428428
429- def popitem (self ) -> typing . Tuple [str , typing .Any ]:
429+ def popitem (self ) -> tuple [str , typing .Any ]:
430430 """
431431 Removes and returns some (key, value) pair
432432 :returns: The (key, value) pair.
@@ -514,9 +514,7 @@ def _serialize(o, format: typing.Optional[str] = None): # pylint: disable=too-m
514514 return o
515515
516516
517- def _get_rest_field (
518- attr_to_rest_field : typing .Dict [str , "_RestField" ], rest_name : str
519- ) -> typing .Optional ["_RestField" ]:
517+ def _get_rest_field (attr_to_rest_field : dict [str , "_RestField" ], rest_name : str ) -> typing .Optional ["_RestField" ]:
520518 try :
521519 return next (rf for rf in attr_to_rest_field .values () if rf ._rest_name == rest_name )
522520 except StopIteration :
@@ -539,7 +537,7 @@ class Model(_MyMutableMapping):
539537 _is_model = True
540538 # label whether current class's _attr_to_rest_field has been calculated
541539 # could not see _attr_to_rest_field directly because subclass inherits it from parent class
542- _calculated : typing . Set [str ] = set ()
540+ _calculated : set [str ] = set ()
543541
544542 def __init__ (self , * args : typing .Any , ** kwargs : typing .Any ) -> None :
545543 class_name = self .__class__ .__name__
@@ -624,7 +622,7 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self:
624622 # we know the last nine classes in mro are going to be 'Model', '_MyMutableMapping', 'MutableMapping',
625623 # 'Mapping', 'Collection', 'Sized', 'Iterable', 'Container' and 'object'
626624 mros = cls .__mro__ [:- 9 ][::- 1 ] # ignore parents, and reverse the mro order
627- attr_to_rest_field : typing . Dict [str , _RestField ] = { # map attribute name to rest_field property
625+ attr_to_rest_field : dict [str , _RestField ] = { # map attribute name to rest_field property
628626 k : v for mro_class in mros for k , v in mro_class .__dict__ .items () if k [0 ] != "_" and hasattr (v , "_type" )
629627 }
630628 annotations = {
@@ -639,7 +637,7 @@ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self:
639637 rf ._type = rf ._get_deserialize_callable_from_annotation (annotations .get (attr , None ))
640638 if not rf ._rest_name_input :
641639 rf ._rest_name_input = attr
642- cls ._attr_to_rest_field : typing . Dict [str , _RestField ] = dict (attr_to_rest_field .items ())
640+ cls ._attr_to_rest_field : dict [str , _RestField ] = dict (attr_to_rest_field .items ())
643641 cls ._calculated .add (f"{ cls .__module__ } .{ cls .__qualname__ } " )
644642
645643 return super ().__new__ (cls )
@@ -681,7 +679,7 @@ def _deserialize(cls, data, exist_discriminators):
681679 mapped_cls = cls .__mapping__ .get (discriminator_value , cls ) # pyright: ignore # pylint: disable=no-member
682680 return mapped_cls ._deserialize (data , exist_discriminators )
683681
684- def as_dict (self , * , exclude_readonly : bool = False ) -> typing . Dict [str , typing .Any ]:
682+ def as_dict (self , * , exclude_readonly : bool = False ) -> dict [str , typing .Any ]:
685683 """Return a dict that can be turned into json using json.dump.
686684
687685 :keyword bool exclude_readonly: Whether to remove the readonly properties.
@@ -741,7 +739,7 @@ def _deserialize_with_union(deserializers, obj):
741739def _deserialize_dict (
742740 value_deserializer : typing .Optional [typing .Callable ],
743741 module : typing .Optional [str ],
744- obj : typing . Dict [typing .Any , typing .Any ],
742+ obj : dict [typing .Any , typing .Any ],
745743):
746744 if obj is None :
747745 return obj
@@ -751,7 +749,7 @@ def _deserialize_dict(
751749
752750
753751def _deserialize_multiple_sequence (
754- entry_deserializers : typing . List [typing .Optional [typing .Callable ]],
752+ entry_deserializers : list [typing .Optional [typing .Callable ]],
755753 module : typing .Optional [str ],
756754 obj ,
757755):
@@ -772,14 +770,14 @@ def _deserialize_sequence(
772770 return type (obj )(_deserialize (deserializer , entry , module ) for entry in obj )
773771
774772
775- def _sorted_annotations (types : typing . List [typing .Any ]) -> typing . List [typing .Any ]:
773+ def _sorted_annotations (types : list [typing .Any ]) -> list [typing .Any ]:
776774 return sorted (
777775 types ,
778776 key = lambda x : hasattr (x , "__name__" ) and x .__name__ .lower () in ("str" , "float" , "int" , "bool" ),
779777 )
780778
781779
782- def _get_deserialize_callable_from_annotation ( # pylint: disable=too-many-return-statements, too-many-branches
780+ def _get_deserialize_callable_from_annotation ( # pylint: disable=too-many-return-statements, too-many-statements, too-many- branches
783781 annotation : typing .Any ,
784782 module : typing .Optional [str ],
785783 rf : typing .Optional ["_RestField" ] = None ,
@@ -844,7 +842,10 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
844842 return functools .partial (_deserialize_with_union , deserializers )
845843
846844 try :
847- if annotation ._name == "Dict" : # pyright: ignore
845+ annotation_name = (
846+ annotation .__name__ if hasattr (annotation , "__name__" ) else annotation ._name # pyright: ignore
847+ )
848+ if annotation_name .lower () == "dict" :
848849 value_deserializer = _get_deserialize_callable_from_annotation (
849850 annotation .__args__ [1 ], module , rf # pyright: ignore
850851 )
@@ -857,7 +858,10 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
857858 except (AttributeError , IndexError ):
858859 pass
859860 try :
860- if annotation ._name in ["List" , "Set" , "Tuple" , "Sequence" ]: # pyright: ignore
861+ annotation_name = (
862+ annotation .__name__ if hasattr (annotation , "__name__" ) else annotation ._name # pyright: ignore
863+ )
864+ if annotation_name .lower () in ["list" , "set" , "tuple" , "sequence" ]:
861865 if len (annotation .__args__ ) > 1 : # pyright: ignore
862866 entry_deserializers = [
863867 _get_deserialize_callable_from_annotation (dt , module , rf )
@@ -975,11 +979,11 @@ def __init__(
975979 name : typing .Optional [str ] = None ,
976980 type : typing .Optional [typing .Callable ] = None , # pylint: disable=redefined-builtin
977981 is_discriminator : bool = False ,
978- visibility : typing .Optional [typing . List [str ]] = None ,
982+ visibility : typing .Optional [list [str ]] = None ,
979983 default : typing .Any = _UNSET ,
980984 format : typing .Optional [str ] = None ,
981985 is_multipart_file_input : bool = False ,
982- xml : typing .Optional [typing . Dict [str , typing .Any ]] = None ,
986+ xml : typing .Optional [dict [str , typing .Any ]] = None ,
983987 ):
984988 self ._type = type
985989 self ._rest_name_input = name
@@ -1037,11 +1041,11 @@ def rest_field(
10371041 * ,
10381042 name : typing .Optional [str ] = None ,
10391043 type : typing .Optional [typing .Callable ] = None , # pylint: disable=redefined-builtin
1040- visibility : typing .Optional [typing . List [str ]] = None ,
1044+ visibility : typing .Optional [list [str ]] = None ,
10411045 default : typing .Any = _UNSET ,
10421046 format : typing .Optional [str ] = None ,
10431047 is_multipart_file_input : bool = False ,
1044- xml : typing .Optional [typing . Dict [str , typing .Any ]] = None ,
1048+ xml : typing .Optional [dict [str , typing .Any ]] = None ,
10451049) -> typing .Any :
10461050 return _RestField (
10471051 name = name ,
@@ -1058,8 +1062,8 @@ def rest_discriminator(
10581062 * ,
10591063 name : typing .Optional [str ] = None ,
10601064 type : typing .Optional [typing .Callable ] = None , # pylint: disable=redefined-builtin
1061- visibility : typing .Optional [typing . List [str ]] = None ,
1062- xml : typing .Optional [typing . Dict [str , typing .Any ]] = None ,
1065+ visibility : typing .Optional [list [str ]] = None ,
1066+ xml : typing .Optional [dict [str , typing .Any ]] = None ,
10631067) -> typing .Any :
10641068 return _RestField (name = name , type = type , is_discriminator = True , visibility = visibility , xml = xml )
10651069
@@ -1078,9 +1082,9 @@ def serialize_xml(model: Model, exclude_readonly: bool = False) -> str:
10781082def _get_element (
10791083 o : typing .Any ,
10801084 exclude_readonly : bool = False ,
1081- parent_meta : typing .Optional [typing . Dict [str , typing .Any ]] = None ,
1085+ parent_meta : typing .Optional [dict [str , typing .Any ]] = None ,
10821086 wrapped_element : typing .Optional [ET .Element ] = None ,
1083- ) -> typing .Union [ET .Element , typing . List [ET .Element ]]:
1087+ ) -> typing .Union [ET .Element , list [ET .Element ]]:
10841088 if _is_model (o ):
10851089 model_meta = getattr (o , "_xml" , {})
10861090
@@ -1169,7 +1173,7 @@ def _get_element(
11691173def _get_wrapped_element (
11701174 v : typing .Any ,
11711175 exclude_readonly : bool ,
1172- meta : typing .Optional [typing . Dict [str , typing .Any ]],
1176+ meta : typing .Optional [dict [str , typing .Any ]],
11731177) -> ET .Element :
11741178 wrapped_element = _create_xml_element (
11751179 meta .get ("name" ) if meta else None , meta .get ("prefix" ) if meta else None , meta .get ("ns" ) if meta else None
@@ -1212,7 +1216,7 @@ def _deserialize_xml(
12121216def _convert_element (e : ET .Element ):
12131217 # dict case
12141218 if len (e .attrib ) > 0 or len ({child .tag for child in e }) > 1 :
1215- dict_result : typing . Dict [str , typing .Any ] = {}
1219+ dict_result : dict [str , typing .Any ] = {}
12161220 for child in e :
12171221 if dict_result .get (child .tag ) is not None :
12181222 if isinstance (dict_result [child .tag ], list ):
@@ -1225,7 +1229,7 @@ def _convert_element(e: ET.Element):
12251229 return dict_result
12261230 # array case
12271231 if len (e ) > 0 :
1228- array_result : typing . List [typing .Any ] = []
1232+ array_result : list [typing .Any ] = []
12291233 for child in e :
12301234 array_result .append (_convert_element (child ))
12311235 return array_result
0 commit comments