gh-124363: Treat debug expressions in f-string as raw strings (#128399)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
Pablo Galindo Salgado 2025-01-22 16:24:54 +00:00 committed by GitHub
parent ba9a4b6215
commit 60a3a0dd6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 44 deletions

View file

@ -1649,6 +1649,14 @@ x = (
#self.assertEqual(f'X{x =}Y', 'Xx\t='+repr(x)+'Y')
#self.assertEqual(f'X{x = }Y', 'Xx\t=\t'+repr(x)+'Y')
def test_debug_expressions_are_raw_strings(self):
self.assertEqual(f'{b"\N{OX}"=}', 'b"\\N{OX}"=b\'\\\\N{OX}\'')
self.assertEqual(f'{r"\xff"=}', 'r"\\xff"=\'\\\\xff\'')
self.assertEqual(f'{r"\n"=}', 'r"\\n"=\'\\\\n\'')
self.assertEqual(f"{'\''=}", "'\\''=\"'\"")
self.assertEqual(f'{'\xc5'=}', r"'\xc5'='Å'")
def test_walrus(self):
x = 20
# This isn't an assignment expression, it's 'x', with a format