@@ -661,15 +661,50 @@ def test_comments(self):
661661 self .assertEqual (f'{ "#" } ' , '#' )
662662 self .assertEqual (f'{ d ["#" ]} ' , 'hash' )
663663
664- self .assertAllRaise (SyntaxError , "f-string expression part cannot include '#'" ,
665- ["f'{1#}'" , # error because the expression becomes "(1#)"
666- "f'{3(#)}'" ,
664+ self .assertAllRaise (SyntaxError , "'{' was never closed" ,
665+ ["f'{1#}'" , # error because everything after '#' is a comment
667666 "f'{#}'" ,
667+ "f'one: {1#}'" ,
668+ "f'{1# one} {2 this is a comment still#}'" ,
668669 ])
669670 self .assertAllRaise (SyntaxError , r"f-string: unmatched '\)'" ,
670671 ["f'{)#}'" , # When wrapped in parens, this becomes
671672 # '()#)'. Make sure that doesn't compile.
672673 ])
674+ self .assertEqual (f'''A complex trick: {
675+ 2 # two
676+ } ''' , 'A complex trick: 2' )
677+ self .assertEqual (f'''
678+ {
679+ 40 # fourty
680+ + # plus
681+ 2 # two
682+ } ''' , '\n 42' )
683+ self .assertEqual (f'''
684+ {
685+ 40 # fourty
686+ + # plus
687+ 2 # two
688+ } ''' , '\n 42' )
689+
690+ self .assertEqual (f'''
691+ # this is not a comment
692+ { # the following operation it's
693+ 3 # this is a number
694+ * 2 } ''' , '\n # this is not a comment\n 6' )
695+ self .assertEqual (f'''
696+ { # f'a {comment}'
697+ 86 # constant
698+ # nothing more
699+ } ''' , '\n 86' )
700+
701+ self .assertAllRaise (SyntaxError , r"f-string: valid expression required before '}'" ,
702+ ["""f'''
703+ {
704+ # only a comment
705+ }'''
706+ """ , # this is equivalent to f'{}'
707+ ])
673708
674709 def test_many_expressions (self ):
675710 # Create a string with many expressions in it. Note that
0 commit comments