1313import types
1414import decimal
1515import unittest
16+ import warnings
1617from test import support
1718from test .support .os_helper import temp_cwd
1819from test .support .script_helper import assert_python_failure , assert_python_ok
@@ -904,7 +905,7 @@ def test_backslashes_in_string_part(self):
904905 self .assertEqual (f'2\x20 3' , '2 3' )
905906 self .assertEqual (f'\x20 3' , ' 3' )
906907
907- with self .assertWarns (DeprecationWarning ): # invalid escape sequence
908+ with self .assertWarns (SyntaxWarning ): # invalid escape sequence
908909 value = eval (r"f'\{6*7}'" )
909910 self .assertEqual (value , '\\ 42' )
910911 with self .assertWarns (SyntaxWarning ): # invalid escape sequence
@@ -1037,7 +1038,7 @@ def test_fstring_backslash_before_double_bracket(self):
10371038 ]
10381039 for case , expected_result in deprecated_cases :
10391040 with self .subTest (case = case , expected_result = expected_result ):
1040- with self .assertWarns (DeprecationWarning ):
1041+ with self .assertWarns (SyntaxWarning ):
10411042 result = eval (case )
10421043 self .assertEqual (result , expected_result )
10431044 self .assertEqual (fr'\{{\}}' , '\\ {\\ }' )
@@ -1046,6 +1047,12 @@ def test_fstring_backslash_before_double_bracket(self):
10461047 self .assertEqual (fr'\}}{ 1 + 1 } ' , '\\ }2' )
10471048 self .assertEqual (fr'{ 1 + 1 } \}}' , '2\\ }' )
10481049
1050+ def test_fstring_backslash_before_double_bracket_warns_once (self ):
1051+ with warnings .catch_warnings (record = True ) as w :
1052+ eval (r"f'\{{'" )
1053+ self .assertEqual (len (w ), 1 )
1054+ self .assertEqual (w [0 ].category , SyntaxWarning )
1055+
10491056 def test_fstring_backslash_prefix_raw (self ):
10501057 self .assertEqual (f'\\ ' , '\\ ' )
10511058 self .assertEqual (f'\\ \\ ' , '\\ \\ ' )
0 commit comments