@@ -481,31 +481,31 @@ def test_literal(self):
481
481
self .assertEqual (f' ' , ' ' )
482
482
483
483
def test_unterminated_string (self ):
484
- self .assertAllRaise (SyntaxError , 'f-string: unterminated string' ,
484
+ self .assertAllRaise (SyntaxError , 'unterminated string' ,
485
485
[r"""f'{"x'""" ,
486
486
r"""f'{"x}'""" ,
487
487
r"""f'{("x'""" ,
488
488
r"""f'{("x}'""" ,
489
489
])
490
490
491
491
def test_mismatched_parens (self ):
492
- self .assertAllRaise (SyntaxError , r"f-string: closing parenthesis '\}' "
492
+ self .assertAllRaise (SyntaxError , r"closing parenthesis '\}' "
493
493
r"does not match opening parenthesis '\('" ,
494
494
["f'{((}'" ,
495
495
])
496
- self .assertAllRaise (SyntaxError , r"f-string: closing parenthesis '\)' "
496
+ self .assertAllRaise (SyntaxError , r"closing parenthesis '\)' "
497
497
r"does not match opening parenthesis '\['" ,
498
498
["f'{a[4)}'" ,
499
499
])
500
- self .assertAllRaise (SyntaxError , r"f-string: closing parenthesis '\]' "
500
+ self .assertAllRaise (SyntaxError , r"closing parenthesis '\]' "
501
501
r"does not match opening parenthesis '\('" ,
502
502
["f'{a(4]}'" ,
503
503
])
504
- self .assertAllRaise (SyntaxError , r"f-string: closing parenthesis '\}' "
504
+ self .assertAllRaise (SyntaxError , r"closing parenthesis '\}' "
505
505
r"does not match opening parenthesis '\['" ,
506
506
["f'{a[4}'" ,
507
507
])
508
- self .assertAllRaise (SyntaxError , r"f-string: closing parenthesis '\}' "
508
+ self .assertAllRaise (SyntaxError , r"closing parenthesis '\}' "
509
509
r"does not match opening parenthesis '\('" ,
510
510
["f'{a(4}'" ,
511
511
])
@@ -573,7 +573,7 @@ def test_compile_time_concat(self):
573
573
self .assertEqual (f'' '' f'' , '' )
574
574
self .assertEqual (f'' '' f'' '' , '' )
575
575
576
- self .assertAllRaise (SyntaxError , "f-string: expecting '}'" ,
576
+ self .assertAllRaise (SyntaxError , "expecting '}'" ,
577
577
["f'{3' f'}'" , # can't concat to get a valid f-string
578
578
])
579
579
@@ -729,7 +729,7 @@ def test_parens_in_expressions(self):
729
729
# are added around it. But we shouldn't go from an invalid
730
730
# expression to a valid one. The added parens are just
731
731
# supposed to allow whitespace (including newlines).
732
- self .assertAllRaise (SyntaxError , 'f-string: invalid syntax' ,
732
+ self .assertAllRaise (SyntaxError , 'invalid syntax' ,
733
733
["f'{,}'" ,
734
734
"f'{,}'" , # this is (,), which is an error
735
735
])
@@ -786,7 +786,7 @@ def test_backslashes_in_string_part(self):
786
786
self .assertEqual (f'2\x20 3' , '2 3' )
787
787
self .assertEqual (f'\x20 3' , ' 3' )
788
788
789
- with self .assertWarns (SyntaxWarning ): # invalid escape sequence
789
+ with self .assertWarns (DeprecationWarning ): # invalid escape sequence
790
790
value = eval (r"f'\{6*7}'" )
791
791
self .assertEqual (value , '\\ 42' )
792
792
self .assertEqual (f'\\ { 6 * 7 } ' , '\\ 42' )
@@ -1091,6 +1091,11 @@ def test_conversions(self):
1091
1091
self .assertEqual (f'{ "a" !r} ' , "'a'" )
1092
1092
self .assertEqual (f'{ "a" !a} ' , "'a'" )
1093
1093
1094
+ # Conversions can have trailing whitespace after them since it
1095
+ # does not provide any significance
1096
+ self .assertEqual (f"{ 3 !s } " , "3" )
1097
+ self .assertEqual (f'{ 3.14 !s :10.10} ' , '3.14 ' )
1098
+
1094
1099
# Not a conversion.
1095
1100
self .assertEqual (f'{ "a!r" } ' , "a!r" )
1096
1101
@@ -1109,12 +1114,18 @@ def test_conversions(self):
1109
1114
"f'{3!:}'" ,
1110
1115
])
1111
1116
1112
- for conv in 'g' , 'A' , '3' , 'G' , '!' , ' s' , 's ' , ' s ' , ' ä' , 'ɐ' , 'ª' :
1117
+ for conv in 'g' , 'A' , '3' , 'G' , '!' , 'ä' , 'ɐ' , 'ª' :
1113
1118
self .assertAllRaise (SyntaxError ,
1114
1119
"f-string: invalid conversion character %r: "
1115
1120
"expected 's', 'r', or 'a'" % conv ,
1116
1121
["f'{3!" + conv + "}'" ])
1117
1122
1123
+ for conv in ' s' , ' s ' :
1124
+ self .assertAllRaise (SyntaxError ,
1125
+ "f-string: conversion type must come right after the"
1126
+ " exclamanation mark" ,
1127
+ ["f'{3!" + conv + "}'" ])
1128
+
1118
1129
self .assertAllRaise (SyntaxError ,
1119
1130
"f-string: invalid conversion character 'ss': "
1120
1131
"expected 's', 'r', or 'a'" ,
0 commit comments