3737
3838TZ_UTC = timezone .utc
3939_T = typing .TypeVar ("_T" )
40+ _NONE_TYPE = type (None )
4041
4142
4243def _timedelta_as_isostr (td : timedelta ) -> str :
@@ -217,7 +218,7 @@ def _deserialize_datetime(attr: typing.Union[str, datetime]) -> datetime:
217218 test_utc = date_obj .utctimetuple ()
218219 if test_utc .tm_year > 9999 or test_utc .tm_year < 1 :
219220 raise OverflowError ("Hit max or min date" )
220- return date_obj
221+ return date_obj # type: ignore[no-any-return]
221222
222223
223224def _deserialize_datetime_rfc7231 (attr : typing .Union [str , datetime ]) -> datetime :
@@ -271,7 +272,7 @@ def _deserialize_time(attr: typing.Union[str, time]) -> time:
271272 """
272273 if isinstance (attr , time ):
273274 return attr
274- return isodate .parse_time (attr )
275+ return isodate .parse_time (attr ) # type: ignore[no-any-return]
275276
276277
277278def _deserialize_bytes (attr ):
@@ -807,6 +808,14 @@ def _deserialize_multiple_sequence(
807808 return type (obj )(_deserialize (deserializer , entry , module ) for entry , deserializer in zip (obj , entry_deserializers ))
808809
809810
811+ def _is_array_encoded_deserializer (deserializer : functools .partial ) -> bool :
812+ return (
813+ isinstance (deserializer , functools .partial )
814+ and isinstance (deserializer .args [0 ], functools .partial )
815+ and deserializer .args [0 ].func == _deserialize_array_encoded # pylint: disable=comparison-with-callable
816+ )
817+
818+
810819def _deserialize_sequence (
811820 deserializer : typing .Optional [typing .Callable ],
812821 module : typing .Optional [str ],
@@ -816,17 +825,19 @@ def _deserialize_sequence(
816825 return obj
817826 if isinstance (obj , ET .Element ):
818827 obj = list (obj )
819- try :
820- if (
821- isinstance (obj , str )
822- and isinstance (deserializer , functools .partial )
823- and isinstance (deserializer .args [0 ], functools .partial )
824- and deserializer .args [0 ].func == _deserialize_array_encoded # pylint: disable=comparison-with-callable
825- ):
826- # encoded string may be deserialized to sequence
828+
829+ # encoded string may be deserialized to sequence
830+ if isinstance (obj , str ) and isinstance (deserializer , functools .partial ):
831+ # for list[str]
832+ if _is_array_encoded_deserializer (deserializer ):
827833 return deserializer (obj )
828- except : # pylint: disable=bare-except
829- pass
834+
835+ # for list[Union[...]]
836+ if isinstance (deserializer .args [0 ], list ):
837+ for sub_deserializer in deserializer .args [0 ]:
838+ if _is_array_encoded_deserializer (sub_deserializer ):
839+ return sub_deserializer (obj )
840+
830841 return type (obj )(_deserialize (deserializer , entry , module ) for entry in obj )
831842
832843
@@ -877,16 +888,16 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur
877888
878889 # is it optional?
879890 try :
880- if any (a for a in annotation .__args__ if a == type ( None ) ): # pyright: ignore
891+ if any (a is _NONE_TYPE for a in annotation .__args__ ): # pyright: ignore
881892 if len (annotation .__args__ ) <= 2 : # pyright: ignore
882893 if_obj_deserializer = _get_deserialize_callable_from_annotation (
883- next (a for a in annotation .__args__ if a != type ( None ) ), module , rf # pyright: ignore
894+ next (a for a in annotation .__args__ if a is not _NONE_TYPE ), module , rf # pyright: ignore
884895 )
885896
886897 return functools .partial (_deserialize_with_optional , if_obj_deserializer )
887898 # the type is Optional[Union[...]], we need to remove the None type from the Union
888899 annotation_copy = copy .copy (annotation )
889- annotation_copy .__args__ = [a for a in annotation_copy .__args__ if a != type ( None ) ] # pyright: ignore
900+ annotation_copy .__args__ = [a for a in annotation_copy .__args__ if a is not _NONE_TYPE ] # pyright: ignore
890901 return _get_deserialize_callable_from_annotation (annotation_copy , module , rf )
891902 except AttributeError :
892903 pass
@@ -1012,7 +1023,7 @@ def _failsafe_deserialize(
10121023) -> typing .Any :
10131024 try :
10141025 return _deserialize (deserializer , response .json (), module , rf , format )
1015- except DeserializationError :
1026+ except Exception : # pylint: disable=broad-except
10161027 _LOGGER .warning (
10171028 "Ran into a deserialization error. Ignoring since this is failsafe deserialization" , exc_info = True
10181029 )
@@ -1025,7 +1036,7 @@ def _failsafe_deserialize_xml(
10251036) -> typing .Any :
10261037 try :
10271038 return _deserialize_xml (deserializer , response .text ())
1028- except DeserializationError :
1039+ except Exception : # pylint: disable=broad-except
10291040 _LOGGER .warning (
10301041 "Ran into a deserialization error. Ignoring since this is failsafe deserialization" , exc_info = True
10311042 )
@@ -1271,7 +1282,7 @@ def _get_wrapped_element(
12711282 _get_element (v , exclude_readonly , meta , wrapped_element )
12721283 else :
12731284 wrapped_element .text = _get_primitive_type_value (v )
1274- return wrapped_element
1285+ return wrapped_element # type: ignore[no-any-return]
12751286
12761287
12771288def _get_primitive_type_value (v ) -> str :
@@ -1284,7 +1295,9 @@ def _get_primitive_type_value(v) -> str:
12841295 return str (v )
12851296
12861297
1287- def _create_xml_element (tag , prefix = None , ns = None ):
1298+ def _create_xml_element (
1299+ tag : typing .Any , prefix : typing .Optional [str ] = None , ns : typing .Optional [str ] = None
1300+ ) -> ET .Element :
12881301 if prefix and ns :
12891302 ET .register_namespace (prefix , ns )
12901303 if ns :
0 commit comments