@@ -129,6 +129,8 @@ def _recursive_sequence_map(f, x):
129129 if isinstance (x , (list , tuple )):
130130 seq_type = type (x )
131131 return seq_type (_recursive_sequence_map (f , xi ) for xi in x )
132+ elif _is_sequence_like (x ):
133+ return [_recursive_sequence_map (f , xi ) for xi in x ]
132134 else :
133135 return f (x )
134136
@@ -721,11 +723,7 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase:
721723 elif _is_numpy_array (expected ):
722724 expected = _as_numpy_array (expected )
723725 cls = ApproxNumpy
724- elif (
725- hasattr (expected , "__getitem__" )
726- and isinstance (expected , Sized )
727- and not isinstance (expected , (str , bytes ))
728- ):
726+ elif _is_sequence_like (expected ):
729727 cls = ApproxSequenceLike
730728 elif isinstance (expected , Collection ) and not isinstance (expected , (str , bytes )):
731729 msg = f"pytest.approx() only supports ordered sequences, but got: { expected !r} "
@@ -736,6 +734,14 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase:
736734 return cls (expected , rel , abs , nan_ok )
737735
738736
737+ def _is_sequence_like (expected : object ) -> bool :
738+ return (
739+ hasattr (expected , "__getitem__" )
740+ and isinstance (expected , Sized )
741+ and not isinstance (expected , (str , bytes ))
742+ )
743+
744+
739745def _is_numpy_array (obj : object ) -> bool :
740746 """
741747 Return true if the given object is implicitly convertible to ndarray,
0 commit comments