gh-135148: Correctly handle f/t strings with comments and debug expressions (#135198)

This commit is contained in:
Pablo Galindo Salgado 2025-07-16 11:47:13 +02:00 committed by GitHub
parent e89923d366
commit ef66fb597b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 83 additions and 20 deletions

View file

@ -1651,6 +1651,18 @@ x = (
self.assertEqual(f"{1+2 = # my comment
}", '1+2 = \n 3')
self.assertEqual(f'{""" # booo
"""=}', '""" # booo\n """=\' # booo\\n \'')
self.assertEqual(f'{" # nooo "=}', '" # nooo "=\' # nooo \'')
self.assertEqual(f'{" \" # nooo \" "=}', '" \\" # nooo \\" "=\' " # nooo " \'')
self.assertEqual(f'{ # some comment goes here
"""hello"""=}', ' \n """hello"""=\'hello\'')
self.assertEqual(f'{"""# this is not a comment
a""" # this is a comment
}', '# this is not a comment\n a')
# These next lines contains tabs. Backslash escapes don't
# work in f-strings.
# patchcheck doesn't like these tabs. So the only way to test