summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-02 12:53:27 (GMT)
committerGitHub <noreply@github.com>2023-06-02 12:53:27 (GMT)
commit103ae4e36e965b2d693c90bb6cb699f845903950 (patch)
tree21fbd59a501b94c8c0db63b7099b94ca590189dd /Lib
parent46cc4f0f76a9f6966aee76d74f8db9a2f43fa8a6 (diff)
downloadcpython-103ae4e36e965b2d693c90bb6cb699f845903950.zip
cpython-103ae4e36e965b2d693c90bb6cb699f845903950.tar.gz
cpython-103ae4e36e965b2d693c90bb6cb699f845903950.tar.bz2
[3.12] gh-105194: Fix format specifier escaped characters in f-strings (GH-105231) (#105234)
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):