Skip to content

Commit e84778a

Browse files
committed
Rename f helper to fstring
1 parent 4f6c5df commit e84778a

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

Lib/test/test_string/_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def convert(value, conversion):
4242
return value
4343

4444

45-
def f(template):
45+
def fstring(template):
4646
parts = []
4747
for item in template:
4848
match item:
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from string.templatelib import Template, Interpolation
22

3-
from test.test_string._support import TStringTestCase, f
3+
from test.test_string._support import TStringTestCase, fstring
44

55

66
class TestTemplate(TStringTestCase):
@@ -10,46 +10,46 @@ def test_basic_creation(self):
1010
t = t'Hello, world'
1111
self.assertIsInstance(t, Template)
1212
self.assertTStringEqual(t, ('Hello, world',), ())
13-
self.assertEqual(f(t), 'Hello, world')
13+
self.assertEqual(fstring(t), 'Hello, world')
1414

1515
# Empty t-string
1616
t = t''
1717
self.assertTStringEqual(t, ('',), ())
18-
self.assertEqual(f(t), '')
18+
self.assertEqual(fstring(t), '')
1919

2020
# Multi-line t-string
2121
t = t"""Hello,
2222
world"""
2323
self.assertEqual(t.strings, ('Hello,\nworld',))
2424
self.assertEqual(len(t.interpolations), 0)
25-
self.assertEqual(f(t), 'Hello,\nworld')
25+
self.assertEqual(fstring(t), 'Hello,\nworld')
2626

2727
def test_creation_interleaving(self):
2828
# Should add strings on either side
2929
t = Template(Interpolation('Maria', 'name', None, ''))
3030
self.assertTStringEqual(t, ('', ''), [('Maria', 'name')])
31-
self.assertEqual(f(t), 'Maria')
31+
self.assertEqual(fstring(t), 'Maria')
3232

3333
# Should prepend empty string
3434
t = Template(Interpolation('Maria', 'name', None, ''), ' is my name')
3535
self.assertTStringEqual(t, ('', ' is my name'), [('Maria', 'name')])
36-
self.assertEqual(f(t), 'Maria is my name')
36+
self.assertEqual(fstring(t), 'Maria is my name')
3737

3838
# Should append empty string
3939
t = Template('Hello, ', Interpolation('Maria', 'name', None, ''))
4040
self.assertTStringEqual(t, ('Hello, ', ''), [('Maria', 'name')])
41-
self.assertEqual(f(t), 'Hello, Maria')
41+
self.assertEqual(fstring(t), 'Hello, Maria')
4242

4343
# Should concatenate strings
4444
t = Template('Hello', ', ', Interpolation('Maria', 'name', None, ''),
4545
'!')
4646
self.assertTStringEqual(t, ('Hello, ', '!'), [('Maria', 'name')])
47-
self.assertEqual(f(t), 'Hello, Maria!')
47+
self.assertEqual(fstring(t), 'Hello, Maria!')
4848

4949
# Should add strings on either side and in between
5050
t = Template(Interpolation('Maria', 'name', None, ''),
5151
Interpolation('Python', 'language', None, ''))
5252
self.assertTStringEqual(
5353
t, ('', '', ''), [('Maria', 'name'), ('Python', 'language')]
5454
)
55-
self.assertEqual(f(t), 'MariaPython')
55+
self.assertEqual(fstring(t), 'MariaPython')

Lib/test/test_tstring.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ast
22
import unittest
33

4-
from test.test_string._support import TStringTestCase, f
4+
from test.test_string._support import TStringTestCase, fstring
55

66

77
class TestTString(TStringTestCase):
@@ -28,7 +28,7 @@ def test_interpolation_basics(self):
2828
name = "Python"
2929
t = t"Hello, {name}"
3030
self.assertTStringEqual(t, ("Hello, ", ""), [(name, "name")])
31-
self.assertEqual(f(t), "Hello, Python")
31+
self.assertEqual(fstring(t), "Hello, Python")
3232

3333
# Multiple interpolations
3434
first = "Python"
@@ -37,14 +37,14 @@ def test_interpolation_basics(self):
3737
self.assertTStringEqual(
3838
t, ("", " ", ""), [(first, 'first'), (last, 'last')]
3939
)
40-
self.assertEqual(f(t), "Python Developer")
40+
self.assertEqual(fstring(t), "Python Developer")
4141

4242
# Interpolation with expressions
4343
a = 10
4444
b = 20
4545
t = t"Sum: {a + b}"
4646
self.assertTStringEqual(t, ("Sum: ", ""), [(a + b, "a + b")])
47-
self.assertEqual(f(t), "Sum: 30")
47+
self.assertEqual(fstring(t), "Sum: 30")
4848

4949
# Interpolation with function
5050
def square(x):
@@ -53,7 +53,7 @@ def square(x):
5353
self.assertTStringEqual(
5454
t, ("Square: ", ""), [(square(5), "square(5)")]
5555
)
56-
self.assertEqual(f(t), "Square: 25")
56+
self.assertEqual(fstring(t), "Square: 25")
5757

5858
# Test attribute access in expressions
5959
class Person:
@@ -68,14 +68,14 @@ def upper(self):
6868
self.assertTStringEqual(
6969
t, ("Name: ", ""), [(person.name, "person.name")]
7070
)
71-
self.assertEqual(f(t), "Name: Alice")
71+
self.assertEqual(fstring(t), "Name: Alice")
7272

7373
# Test method calls
7474
t = t"Name: {person.upper()}"
7575
self.assertTStringEqual(
7676
t, ("Name: ", ""), [(person.upper(), "person.upper()")]
7777
)
78-
self.assertEqual(f(t), "Name: ALICE")
78+
self.assertEqual(fstring(t), "Name: ALICE")
7979

8080
# Test dictionary access
8181
data = {"name": "Bob", "age": 30}
@@ -84,7 +84,7 @@ def upper(self):
8484
t, ("Name: ", ", Age: ", ""),
8585
[(data["name"], "data['name']"), (data["age"], "data['age']")],
8686
)
87-
self.assertEqual(f(t), "Name: Bob, Age: 30")
87+
self.assertEqual(fstring(t), "Name: Bob, Age: 30")
8888

8989
def test_format_specifiers(self):
9090
# Test basic format specifiers
@@ -93,25 +93,25 @@ def test_format_specifiers(self):
9393
self.assertTStringEqual(
9494
t, ("Pi: ", ""), [(value, "value", None, ".2f")]
9595
)
96-
self.assertEqual(f(t), "Pi: 3.14")
96+
self.assertEqual(fstring(t), "Pi: 3.14")
9797

9898
def test_conversions(self):
9999
# Test !s conversion (str)
100100
obj = object()
101101
t = t"Object: {obj!s}"
102102
self.assertTStringEqual(t, ("Object: ", ""), [(obj, "obj", "s")])
103-
self.assertEqual(f(t), f"Object: {str(obj)}")
103+
self.assertEqual(fstring(t), f"Object: {str(obj)}")
104104

105105
# Test !r conversion (repr)
106106
t = t"Data: {obj!r}"
107107
self.assertTStringEqual(t, ("Data: ", ""), [(obj, "obj", "r")])
108-
self.assertEqual(f(t), f"Data: {repr(obj)}")
108+
self.assertEqual(fstring(t), f"Data: {repr(obj)}")
109109

110110
# Test !a conversion (ascii)
111111
text = "Café"
112112
t = t"ASCII: {text!a}"
113113
self.assertTStringEqual(t, ("ASCII: ", ""), [(text, "text", "a")])
114-
self.assertEqual(f(t), f"ASCII: {ascii(text)}")
114+
self.assertEqual(fstring(t), f"ASCII: {ascii(text)}")
115115

116116
# Test !z conversion (error)
117117
num = 1
@@ -125,14 +125,14 @@ def test_debug_specifier(self):
125125
self.assertTStringEqual(
126126
t, ("Value: value=", ""), [(value, "value", "r")]
127127
)
128-
self.assertEqual(f(t), "Value: value=42")
128+
self.assertEqual(fstring(t), "Value: value=42")
129129

130130
# Test debug specifier with format (conversion default to !r)
131131
t = t"Value: {value=:.2f}"
132132
self.assertTStringEqual(
133133
t, ("Value: value=", ""), [(value, "value", None, ".2f")]
134134
)
135-
self.assertEqual(f(t), "Value: value=42.00")
135+
self.assertEqual(fstring(t), "Value: value=42.00")
136136

137137
# Test debug specifier with conversion
138138
t = t"Value: {value=!s}"
@@ -145,13 +145,13 @@ def test_debug_specifier(self):
145145
self.assertTStringEqual(
146146
t, ("Value: value = ", ""), [(value, "value", "r")]
147147
)
148-
self.assertEqual(f(t), "Value: value = 42")
148+
self.assertEqual(fstring(t), "Value: value = 42")
149149

150150
def test_raw_tstrings(self):
151151
path = r"C:\Users"
152152
t = rt"{path}\Documents"
153153
self.assertTStringEqual(t, ("", r"\Documents"), [(path, "path")])
154-
self.assertEqual(f(t), r"C:\Users\Documents")
154+
self.assertEqual(fstring(t), r"C:\Users\Documents")
155155

156156
# Test alternative prefix
157157
t = tr"{path}\Documents"
@@ -164,26 +164,26 @@ def test_template_concatenation(self):
164164
t2 = t"world"
165165
combined = t1 + t2
166166
self.assertTStringEqual(combined, ("Hello, world",), ())
167-
self.assertEqual(f(combined), "Hello, world")
167+
self.assertEqual(fstring(combined), "Hello, world")
168168

169169
# Test template + string
170170
t1 = t"Hello"
171171
combined = t1 + ", world"
172172
self.assertTStringEqual(combined, ("Hello, world",), ())
173-
self.assertEqual(f(combined), "Hello, world")
173+
self.assertEqual(fstring(combined), "Hello, world")
174174

175175
# Test template + template with interpolation
176176
name = "Python"
177177
t1 = t"Hello, "
178178
t2 = t"{name}"
179179
combined = t1 + t2
180180
self.assertTStringEqual(combined, ("Hello, ", ""), [(name, "name")])
181-
self.assertEqual(f(combined), "Hello, Python")
181+
self.assertEqual(fstring(combined), "Hello, Python")
182182

183183
# Test string + template
184184
t = "Hello, " + t"{name}"
185185
self.assertTStringEqual(t, ("Hello, ", ""), [(name, "name")])
186-
self.assertEqual(f(t), "Hello, Python")
186+
self.assertEqual(fstring(t), "Hello, Python")
187187

188188
def test_nested_templates(self):
189189
# Test a template inside another template expression
@@ -251,51 +251,51 @@ def test_literal_concatenation(self):
251251
# Test concatenation of t-string literals
252252
t = t"Hello, " t"world"
253253
self.assertTStringEqual(t, ("Hello, world",), ())
254-
self.assertEqual(f(t), "Hello, world")
254+
self.assertEqual(fstring(t), "Hello, world")
255255

256256
# Test concatenation with interpolation
257257
name = "Python"
258258
t = t"Hello, " t"{name}"
259259
self.assertTStringEqual(t, ("Hello, ", ""), [(name, "name")])
260-
self.assertEqual(f(t), "Hello, Python")
260+
self.assertEqual(fstring(t), "Hello, Python")
261261

262262
# Test concatenation with string literal
263263
name = "Python"
264264
t = t"Hello, {name}" "and welcome!"
265265
self.assertTStringEqual(
266266
t, ("Hello, ", "and welcome!"), [(name, "name")]
267267
)
268-
self.assertEqual(f(t), "Hello, Pythonand welcome!")
268+
self.assertEqual(fstring(t), "Hello, Pythonand welcome!")
269269

270270
# Test concatenation with Unicode literal
271271
name = "Python"
272272
t = t"Hello, {name}" u"and welcome!"
273273
self.assertTStringEqual(
274274
t, ("Hello, ", "and welcome!"), [(name, "name")]
275275
)
276-
self.assertEqual(f(t), "Hello, Pythonand welcome!")
276+
self.assertEqual(fstring(t), "Hello, Pythonand welcome!")
277277

278278
# Test concatenation with f-string literal
279279
tab = '\t'
280280
t = t"Tab: {tab}. " f"f-tab: {tab}."
281281
self.assertTStringEqual(t, ("Tab: ", ". f-tab: \t."), [(tab, "tab")])
282-
self.assertEqual(f(t), "Tab: \t. f-tab: \t.")
282+
self.assertEqual(fstring(t), "Tab: \t. f-tab: \t.")
283283

284284
# Test concatenation with raw string literal
285285
tab = '\t'
286286
t = t"Tab: {tab}. " r"Raw tab: \t."
287287
self.assertTStringEqual(
288288
t, ("Tab: ", r". Raw tab: \t."), [(tab, "tab")]
289289
)
290-
self.assertEqual(f(t), "Tab: \t. Raw tab: \\t.")
290+
self.assertEqual(fstring(t), "Tab: \t. Raw tab: \\t.")
291291

292292
# Test concatenation with raw f-string literal
293293
tab = '\t'
294294
t = t"Tab: {tab}. " rf"f-tab: {tab}. Raw tab: \t."
295295
self.assertTStringEqual(
296296
t, ("Tab: ", ". f-tab: \t. Raw tab: \\t."), [(tab, "tab")]
297297
)
298-
self.assertEqual(f(t), "Tab: \t. f-tab: \t. Raw tab: \\t.")
298+
self.assertEqual(fstring(t), "Tab: \t. f-tab: \t. Raw tab: \\t.")
299299

300300
what = 't'
301301
expected_msg = 'cannot mix bytes and nonbytes literals'
@@ -315,7 +315,7 @@ def test_triple_quoted(self):
315315
self.assertTStringEqual(
316316
t, ("\n Hello,\n world\n ",), ()
317317
)
318-
self.assertEqual(f(t), "\n Hello,\n world\n ")
318+
self.assertEqual(fstring(t), "\n Hello,\n world\n ")
319319

320320
# Test triple-quoted with interpolation
321321
name = "Python"
@@ -326,7 +326,7 @@ def test_triple_quoted(self):
326326
self.assertTStringEqual(
327327
t, ("\n Hello,\n ", "\n "), [(name, "name")]
328328
)
329-
self.assertEqual(f(t), "\n Hello,\n Python\n ")
329+
self.assertEqual(fstring(t), "\n Hello,\n Python\n ")
330330

331331
if __name__ == '__main__':
332332
unittest.main()

0 commit comments

Comments
 (0)