@@ -663,33 +663,51 @@ def test_missing_expression(self):
663
663
["f'{}'" ,
664
664
"f'{ }'"
665
665
"f' {} '" ,
666
- "f'{!r}'" ,
667
- "f'{ !r}'" ,
668
666
"f'{10:{ }}'" ,
669
667
"f' { } '" ,
670
668
671
669
# The Python parser ignores also the following
672
670
# whitespace characters in additional to a space.
673
671
"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:'" ,
674
685
675
- # Catch the empty expression before the
686
+ # Catch empty expression before the
676
687
# invalid conversion.
677
688
"f'{!x}'" ,
678
689
"f'{ !xr}'" ,
679
690
"f'{!x:}'" ,
680
691
"f'{!x:a}'" ,
681
692
"f'{ !xr:}'" ,
682
693
"f'{ !xr:a}'" ,
694
+ ])
683
695
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}'''" ,
691
701
"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'{='" ,
693
711
])
694
712
695
713
# Different error message is raised for other whitespace characters.
@@ -820,10 +838,10 @@ def test_no_escapes_for_braces(self):
820
838
Only literal curly braces begin an expression.
821
839
"""
822
840
# \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}' )
827
845
828
846
def test_newlines_in_expressions (self ):
829
847
self .assertEqual (f'{ 0 } ' , '0' )
0 commit comments