Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,11 @@ def __repr__(self):

self.assertEqual(f'{" # nooo "=}', '" # nooo "=\' # nooo \'')
self.assertEqual(f'{" \" # nooo \" "=}', '" \\" # nooo \\" "=\' " # nooo " \'')

# A real comment after a string that ends with an escaped quote must
# still be stripped (gh-154711).
self.assertEqual(f"{'\'' = # comment
}", "'\\'' = \n" + repr("'"))
self.assertEqual(f'{"""a" # inside"""=}',
'"""a" # inside"""=\'a" # inside\'')
self.assertEqual(f"{'''a' # inside'''=}",
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_tstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ def test_interpolation_expression_with_reconstructed_metadata(self):
self.assertEqual(regular.interpolations[0].expression, expected)
self.assertEqual(debug.interpolations[0].expression, expected)

def test_comment_after_escaped_quote(self):
# A comment after a string that ends with an escaped quote must be
# stripped from the interpolation expression (gh-154711).
t = t"{'a\'b' # comment
}"
self.assertEqual(t.interpolations[0].expression, "'a\\'b' \n")

t = t"{'a\'b' = # comment
}"
self.assertEqual(t.interpolations[0].expression, "'a\\'b' ")
self.assertEqual(t.strings, ("'a\\'b' = \n", ""))

def test_raw_tstrings(self):
path = r"C:\Users"
t = rt"{path}\Documents"
Expand Down
Loading