@@ -663,33 +663,51 @@ def test_missing_expression(self):
663663 ["f'{}'" ,
664664 "f'{ }'"
665665 "f' {} '" ,
666- "f'{!r}'" ,
667- "f'{ !r}'" ,
668666 "f'{10:{ }}'" ,
669667 "f' { } '" ,
670668
671669 # The Python parser ignores also the following
672670 # whitespace characters in additional to a space.
673671 "f'''{\t \f \r \n }'''" ,
672+ ])
673+
674+ # Different error messeges are raised when a specfier ('!', ':' or '=') is used after an empty expression
675+ self .assertAllRaise (SyntaxError , "f-string: expression required before '!'" ,
676+ ["f'{!r}'" ,
677+ "f'{ !r}'" ,
678+ "f'{!}'" ,
679+ "f'''{\t \f \r \n !a}'''" ,
680+
681+ # Catch empty expression before the
682+ # missing closing brace.
683+ "f'{!'" ,
684+ "f'{!s:'" ,
674685
675- # Catch the empty expression before the
686+ # Catch empty expression before the
676687 # invalid conversion.
677688 "f'{!x}'" ,
678689 "f'{ !xr}'" ,
679690 "f'{!x:}'" ,
680691 "f'{!x:a}'" ,
681692 "f'{ !xr:}'" ,
682693 "f'{ !xr:a}'" ,
694+ ])
683695
684- "f'{!}'" ,
685- "f'{:}'" ,
686-
687- # We find the empty expression before the
688- # missing closing brace.
689- "f'{!'" ,
690- "f'{!s:'" ,
696+ self .assertAllRaise (SyntaxError , "f-string: expression required before ':'" ,
697+ ["f'{:}'" ,
698+ "f'{ :!}'" ,
699+ "f'{:2}'" ,
700+ "f'''{\t \f \r \n :a}'''" ,
691701 "f'{:'" ,
692- "f'{:x'" ,
702+ ])
703+
704+ self .assertAllRaise (SyntaxError , "f-string: expression required before '='" ,
705+ ["f'{=}'" ,
706+ "f'{ =}'" ,
707+ "f'{ =:}'" ,
708+ "f'{ =!}'" ,
709+ "f'''{\t \f \r \n =}'''" ,
710+ "f'{='" ,
693711 ])
694712
695713 # Different error message is raised for other whitespace characters.
@@ -820,10 +838,10 @@ def test_no_escapes_for_braces(self):
820838 Only literal curly braces begin an expression.
821839 """
822840 # \x7b is '{'.
823- # TODO: RUSTPYTHON self.assertEqual(f'\x7b1+1}}', '{1+1}')
824- # TODO: RUSTPYTHON self.assertEqual(f'\x7b1+1', '{1+1')
825- # TODO: RUSTPYTHON self.assertEqual(f'\u007b1+1', '{1+1')
826- # TODO: RUSTPYTHON self.assertEqual(f'\N{LEFT CURLY BRACKET}1+1\N{RIGHT CURLY BRACKET}', '{1+1}')
841+ self .assertEqual (f'\x7b 1+1}}' , '{1+1}' )
842+ self .assertEqual (f'\x7b 1+1' , '{1+1' )
843+ self .assertEqual (f'\u007b 1+1' , '{1+1' )
844+ self .assertEqual (f'\N{LEFT CURLY BRACKET} 1+1\N{RIGHT CURLY BRACKET} ' , '{1+1}' )
827845
828846 def test_newlines_in_expressions (self ):
829847 self .assertEqual (f'{ 0 } ' , '0' )
0 commit comments