@@ -946,7 +946,9 @@ def test_decoder_fuzz(self):
946946 self .bjdloadb (pack (fmt , i ))
947947 except DecoderException :
948948 pass
949- except Exception as ex : # pragma: no cover pylint: disable=broad-except
949+ except (
950+ Exception
951+ ) as ex : # pragma: no cover pylint: disable=broad-except
950952 self .fail ("Unexpected failure: %s" % ex )
951953
952954 def assert_raises_regex (self , * args , ** kwargs ):
@@ -958,18 +960,25 @@ def assert_raises_regex(self, *args, **kwargs):
958960 def test_recursion (self ):
959961 old_limit = getrecursionlimit ()
960962 setrecursionlimit (200 )
963+ if version_info >= (3 , 5 ):
964+ # Python 3.5+ has RecursionError
965+ recursion_exceptions = (RuntimeError , RecursionError )
966+ else :
967+ # Python 2.7 and early Python 3.x only have RuntimeError
968+ recursion_exceptions = (RuntimeError ,)
969+
961970 try :
962971 obj = current = []
963- # Increase the multiplier for Python 3.12+
964- multiplier = 4 if version_info >= (3 , 12 ) else 2
965- for _ in range (getrecursionlimit () * multiplier ):
972+ for _ in range (getrecursionlimit () * 2 ):
966973 new_list = []
967974 current .append (new_list )
968975 current = new_list
969- with self .assert_raises_regex (RuntimeError , "recursion" ):
976+
977+ with self .assert_raises_regex (recursion_exceptions , "recursion" ):
970978 self .bjddumpb (obj )
971- raw = ARRAY_START * (getrecursionlimit () * multiplier )
972- with self .assert_raises_regex (RuntimeError , "recursion" ):
979+
980+ raw = ARRAY_START * (getrecursionlimit () * 2 )
981+ with self .assert_raises_regex (recursion_exceptions , "recursion" ):
973982 self .bjdloadb (raw )
974983 finally :
975984 setrecursionlimit (old_limit )
0 commit comments