@@ -627,23 +627,33 @@ def test_mismatched_parens(self):
627627 r"does not match opening parenthesis '\('" ,
628628 ["f'{a(4}'" ,
629629 ])
630- self .assertRaises (SyntaxError , eval , "f'{" + "(" * 100 + "}'" )
630+ self .assertRaises (SyntaxError , eval , "f'{" + "(" * 20 + "}'" )
631631
632632 @unittest .skipIf (support .is_wasi , "exhausts limited stack on WASI" )
633633 def test_fstring_nested_too_deeply (self ):
634- self .assertAllRaise (SyntaxError ,
635- "f-string: expressions nested too deeply" ,
636- ['f"{1+2:{1+2:{1+1:{1}}}}"' ])
634+ def raises_syntax_or_memory_error (txt ):
635+ try :
636+ eval (txt )
637+ self .fail ("No exception raised" )
638+ except SyntaxError :
639+ pass
640+ except MemoryError :
641+ pass
642+ except Exception as ex :
643+ self .fail (f"Should raise SyntaxError or MemoryError, not { type (ex )} " )
644+
645+ raises_syntax_or_memory_error ('f"{1+2:{1+2:{1+1:{1}}}}"' )
637646
638647 def create_nested_fstring (n ):
639648 if n == 0 :
640649 return "1+1"
641650 prev = create_nested_fstring (n - 1 )
642651 return f'f"{{{ prev } }}"'
643652
644- self .assertAllRaise (SyntaxError ,
645- "too many nested f-strings" ,
646- [create_nested_fstring (160 )])
653+ raises_syntax_or_memory_error (create_nested_fstring (160 ))
654+ raises_syntax_or_memory_error ("f'{" + "(" * 100 + "}'" )
655+ raises_syntax_or_memory_error ("f'{" + "(" * 1000 + "}'" )
656+ raises_syntax_or_memory_error ("f'{" + "(" * 10_000 + "}'" )
647657
648658 def test_syntax_error_in_nested_fstring (self ):
649659 # See gh-104016 for more information on this crash
0 commit comments