9595 }
9696)
9797
98+ _FAST_SEQUENCE_EQ_TYPES : frozenset [type [Any ]] = _IDENTITY_EQ_TYPES | frozenset ({float , str })
99+
98100_EQUALITY_TYPES = (
99101 int ,
100102 bool ,
@@ -223,7 +225,20 @@ def comparator(orig: Any, new: Any, superset_obj: bool = False) -> bool:
223225 if orig_type is list or orig_type is tuple :
224226 if len (orig ) != len (new ):
225227 return False
226- return all (comparator (elem1 , elem2 , superset_obj ) for elem1 , elem2 in zip (orig , new ))
228+ if orig :
229+ all_fast_scalars = True
230+ for idx , elem1 in enumerate (orig ):
231+ elem_type = type (elem1 )
232+ if elem_type is not type (new [idx ]) or elem_type not in _FAST_SEQUENCE_EQ_TYPES :
233+ all_fast_scalars = False
234+ break
235+ if all_fast_scalars and orig == new :
236+ return True
237+
238+ for idx , elem1 in enumerate (orig ):
239+ if not comparator (elem1 , new [idx ], superset_obj ):
240+ return False
241+ return True
227242 if orig_type is dict :
228243 if superset_obj :
229244 return all (k in new and comparator (v , new [k ], superset_obj ) for k , v in orig .items ())
@@ -236,6 +251,8 @@ def comparator(orig: Any, new: Any, superset_obj: bool = False) -> bool:
236251 return False
237252 return True
238253 if orig_type is float :
254+ if orig == new :
255+ return True
239256 if math .isnan (orig ) and math .isnan (new ):
240257 return True
241258 return math .isclose (orig , new )
0 commit comments