Debian Codegraph @

tests/data/cases/pep_701.py

raw
1 # flags: --minimum-version=3.12
2 x = f"foo"
3 x = f'foo'
4 x = f"""foo"""
5 x = f'''foo'''
6 x = f"foo {{ bar {{ baz"
7 x = f"foo {{ {2 + 2}bar {{ baz"
8 x = f'foo {{ {2 + 2}bar {{ baz'
9 x = f"""foo {{ {2 + 2}bar {{ baz"""
10 x = f'''foo {{ {2 + 2}bar {{ baz'''
11
12 # edge case: FSTRING_MIDDLE containing only whitespace should not be stripped
13 x = f"{a} {b}"
14
15 x = f"foo {
16 2 + 2
17 } bar baz"
18
19 x = f"foo {{ {"a {2 + 2} b"}bar {{ baz"
20 x = f"foo {{ {f'a {2 + 2} b'}bar {{ baz"
21 x = f"foo {{ {f"a {2 + 2} b"}bar {{ baz"
22
23 x = f"foo {{ {f'a {f"a {2 + 2} b"} b'}bar {{ baz"
24 x = f"foo {{ {f"a {f"a {2 + 2} b"} b"}bar {{ baz"
25
26 x = """foo {{ {2 + 2}bar
27 baz"""
28
29
30 x = f"""foo {{ {2 + 2}bar {{ baz"""
31
32 x = f"""foo {{ {
33 2 + 2
34 }bar {{ baz"""
35
36
37 x = f"""foo {{ {
38 2 + 2
39 }bar
40 baz"""
41
42 x = f"""foo {{ a
43 foo {2 + 2}bar {{ baz
44
45 x = f"foo {{ {
46 2 + 2 # comment
47 }bar"
48
49 {{ baz
50
51 }} buzz
52
53 {print("abc" + "def"
54 )}
55 abc"""
56
57 # edge case: end triple quotes at index zero
58 f"""foo {2+2} bar
59 """
60
61 f' \' {f"'"} \' '
62 f" \" {f'"'} \" "
63
64 x = f"a{2+2:=^72}b"
65 x = f"a{2+2:x}b"
66
67 rf'foo'
68 rf'{foo}'
69
70 f"{x:{y}d}"
71
72 x = f"a{2+2:=^{x}}b"
73 x = f"a{2+2:=^{foo(x+y**2):something else}}b"
74 x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
75 f'{(abc:=10)}'
76
77 f"""This is a really long string, but just make sure that you reflow fstrings {
78 2+2:d
79 }"""
80 f"This is a really long string, but just make sure that you reflow fstrings correctly {2+2:d}"
81
82 f"{2+2=}"
83 f"{2+2 = }"
84 f"{ 2 + 2 = }"
85
86 f"""foo {
87 datetime.datetime.now():%Y
88 %m
89 %d
90 }"""
91
92 f"{
93 X
94 !r
95 }"
96
97 raise ValueError(
98 "xxxxxxxxxxxIncorrect --line-ranges format, expect START-END, found"
99 f" {lines_str!r}"
100 )
101
102 f"`escape` only permitted in {{'html', 'latex', 'latex-math'}}, \
103 got {escape}"
104
105 x = f'\N{GREEK CAPITAL LETTER DELTA} \N{SNOWMAN} {x}'
106 fr'\{{\}}'
107
108 f"""
109 WITH {f'''
110 {1}_cte AS ()'''}
111 """
112
113 value: str = f'''foo
114 '''
115
116 log(
117 f"Received operation {server_operation.name} from "
118 f"{self.writer._transport.get_extra_info('peername')}", # type: ignore[attr-defined]
119 level=0,
120 )
121
122 f"{1:{f'{2}'}}"
123 f'{1:{f'{2}'}}'
124 f'{1:{2}d}'
125
126 f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
127
128 f"""{'''
129 '''}"""
130
131 f"{'\''}"
132 f"{f'\''}"
133
134 f'{1}\{{'
135 f'{2} foo \{{[\}}'
136 f'\{3}'
137 rf"\{"a"}"
138
139 # output
140
141 x = f"foo"
142 x = f"foo"
143 x = f"""foo"""
144 x = f"""foo"""
145 x = f"foo {{ bar {{ baz"
146 x = f"foo {{ {2 + 2}bar {{ baz"
147 x = f"foo {{ {2 + 2}bar {{ baz"
148 x = f"""foo {{ {2 + 2}bar {{ baz"""
149 x = f"""foo {{ {2 + 2}bar {{ baz"""
150
151 # edge case: FSTRING_MIDDLE containing only whitespace should not be stripped
152 x = f"{a} {b}"
153
154 x = f"foo {
155 2 + 2
156 } bar baz"
157
158 x = f"foo {{ {"a {2 + 2} b"}bar {{ baz"
159 x = f"foo {{ {f'a {2 + 2} b'}bar {{ baz"
160 x = f"foo {{ {f"a {2 + 2} b"}bar {{ baz"
161
162 x = f"foo {{ {f'a {f"a {2 + 2} b"} b'}bar {{ baz"
163 x = f"foo {{ {f"a {f"a {2 + 2} b"} b"}bar {{ baz"
164
165 x = """foo {{ {2 + 2}bar
166 baz"""
167
168
169 x = f"""foo {{ {2 + 2}bar {{ baz"""
170
171 x = f"""foo {{ {
172 2 + 2
173 }bar {{ baz"""
174
175
176 x = f"""foo {{ {
177 2 + 2
178 }bar
179 baz"""
180
181 x = f"""foo {{ a
182 foo {2 + 2}bar {{ baz
183
184 x = f"foo {{ {
185 2 + 2 # comment
186 }bar"
187
188 {{ baz
189
190 }} buzz
191
192 {print("abc" + "def"
193 )}
194 abc"""
195
196 # edge case: end triple quotes at index zero
197 f"""foo {2+2} bar
198 """
199
200 f' \' {f"'"} \' '
201 f" \" {f'"'} \" "
202
203 x = f"a{2+2:=^72}b"
204 x = f"a{2+2:x}b"
205
206 rf"foo"
207 rf"{foo}"
208
209 f"{x:{y}d}"
210
211 x = f"a{2+2:=^{x}}b"
212 x = f"a{2+2:=^{foo(x+y**2):something else}}b"
213 x = f"a{2+2:=^{foo(x+y**2):something else}one more}b"
214 f"{(abc:=10)}"
215
216 f"""This is a really long string, but just make sure that you reflow fstrings {
217 2+2:d
218 }"""
219 f"This is a really long string, but just make sure that you reflow fstrings correctly {2+2:d}"
220
221 f"{2+2=}"
222 f"{2+2 = }"
223 f"{ 2 + 2 = }"
224
225 f"""foo {
226 datetime.datetime.now():%Y
227 %m
228 %d
229 }"""
230
231 f"{
232 X
233 !r
234 }"
235
236 raise ValueError(
237 "xxxxxxxxxxxIncorrect --line-ranges format, expect START-END, found"
238 f" {lines_str!r}"
239 )
240
241 f"`escape` only permitted in {{'html', 'latex', 'latex-math'}}, \
242 got {escape}"
243
244 x = f"\N{GREEK CAPITAL LETTER DELTA} \N{SNOWMAN} {x}"
245 rf"\{{\}}"
246
247 f"""
248 WITH {f'''
249 {1}_cte AS ()'''}
250 """
251
252 value: str = f"""foo
253 """
254
255 log(
256 f"Received operation {server_operation.name} from "
257 f"{self.writer._transport.get_extra_info('peername')}", # type: ignore[attr-defined]
258 level=0,
259 )
260
261 f"{1:{f'{2}'}}"
262 f"{1:{f'{2}'}}"
263 f"{1:{2}d}"
264
265 f'{{\\"kind\\":\\"ConfigMap\\",\\"metadata\\":{{\\"annotations\\":{{}},\\"name\\":\\"cluster-info\\",\\"namespace\\":\\"amazon-cloudwatch\\"}}}}'
266
267 f"""{'''
268 '''}"""
269
270 f"{'\''}"
271 f"{f'\''}"
272
273 f"{1}\{{"
274 f"{2} foo \{{[\}}"
275 f"\{3}"
276 rf"\{"a"}"