gh-105194: Fix format specifier escaped characters in f-strings (#105231)

This commit is contained in:
Pablo Galindo Salgado 2023-06-02 13:33:26 +02:00 committed by GitHub
parent 4bfa01b9d9
commit 41de54378d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 2 deletions

View file

@ -764,6 +764,16 @@ x = (
"""f'{"s"!{"r"}}'""",
])
def test_custom_format_specifier(self):
class CustomFormat:
def __format__(self, format_spec):
return format_spec
self.assertEqual(f'{CustomFormat():\n}', '\n')
self.assertEqual(f'{CustomFormat():\u2603}', '')
with self.assertWarns(SyntaxWarning):
exec('f"{F():¯\_(ツ)_/¯}"', {'F': CustomFormat})
def test_side_effect_order(self):
class X:
def __init__(self):