mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
gh-105194: Fix format specifier escaped characters in f-strings (#105231)
This commit is contained in:
parent
4bfa01b9d9
commit
41de54378d
6 changed files with 34 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue