summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2023-06-02 11:33:26 (GMT)
committerGitHub <noreply@github.com>2023-06-02 11:33:26 (GMT)
commit41de54378d54f7ffc38f07db4219e80f48c4249e (patch)
tree42b56206d421d532fb2ac1a9cce7a31458ab26c4 /Lib
parent4bfa01b9d911ce9358cf1a453bee15554f8e4c07 (diff)
downloadcpython-41de54378d54f7ffc38f07db4219e80f48c4249e.zip
cpython-41de54378d54f7ffc38f07db4219e80f48c4249e.tar.gz
cpython-41de54378d54f7ffc38f07db4219e80f48c4249e.tar.bz2
gh-105194: Fix format specifier escaped characters in f-strings (#105231)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_fstring.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index 3ba2f94..031b94d 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -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):