@@ -18,25 +18,25 @@ multiline string literals.
1818Dedented multiline strings use a new prefix "d" (shorthand for "dedent") before
1919the opening quote of a multiline string literal.
2020
21- Example (spaces are visualized as ``_ ``):
21+ Example (spaces are visualized as ``. ``):
2222
2323.. code-block :: python
2424
2525 def hello_paragraph () -> str :
26- ____return d"""
27- ________ <p>
28- __________Hello , World!
29- ________ </p>
30- ____ """
26+ ... . return d"""
27+ ........ <p>
28+ ..........Hello , World!
29+ ........ </p>
30+ .... """
3131
3232 Unlike ``textwrap.dedent() ``, indentation before closing quotes is also
3333considered when determining the amount of indentation to be removed.
3434Therefore, the string returned in the example above consists of the following
3535three lines.
3636
37- * ``"____ <p>\n" ``
38- * ``"______Hello , World!\n" ``
39- * ``"____ </p>\n" ``
37+ * ``".... <p>\n" ``
38+ * ``"......Hello , World!\n" ``
39+ * ``".... </p>\n" ``
4040
4141
4242Motivation
@@ -149,94 +149,94 @@ Examples:
149149 s = d""" """ # SyntaxError: d-string must start with a newline
150150 s = d""" Hello""" # SyntaxError: d-string must start with a newline
151151 s = d""" Hello
152- __World !
152+ ..World !
153153 """ # SyntaxError: d-string must start with a newline
154154
155155 # d-string removes the longest common indentation from each line.
156156 # Empty lines are ignored, but closing quotes line is always considered.
157157 s = d"""
158- __Hello
159- __World !
160- __ """
158+ ..Hello
159+ ..World !
160+ .. """
161161 print (repr (s)) # 'Hello\nWorld!\n'
162162
163163 s = d"""
164- __Hello
165- __World !
166- _ """
167- print (repr (s)) # '_Hello\n_World !\n'
164+ ..Hello
165+ ..World !
166+ . """
167+ print (repr (s)) # '.Hello\n.World !\n'
168168
169169 s = d"""
170- __Hello
171- __World !
170+ ..Hello
171+ ..World !
172172 """
173- print (repr (s)) # '__Hello\n__World !\n'
173+ print (repr (s)) # '..Hello\n..World !\n'
174174
175175 s = d"""
176- __Hello
177- _
176+ ..Hello
177+ .
178178
179- __World !
180- ___ """ # Longest common indentation is '__ '.
181- print (repr (s)) # 'Hello\n\n\nWorld!\n_ '
179+ ..World !
180+ ... """ # Longest common indentation is '.. '.
181+ print (repr (s)) # 'Hello\n\n\nWorld!\n. '
182182
183183 # Closing qutotes can be on the same line as the last content line.
184184 # In this case, the string does not end with a newline.
185185 s = d"""
186- __Hello
187- __World !"""
186+ ..Hello
187+ ..World !"""
188188 print (repr (s)) # 'Hello\nWorld!'
189189
190190 # Tabs are allowed as indentation.
191191 # But tabs and spaces are treated as different characters.
192192 s = d"""
193- --->__Hello
194- --->__World !
193+ --->..Hello
194+ --->..World !
195195 --->"""
196- print (repr (s)) # '__Hello\n__World !\n'
196+ print (repr (s)) # '..Hello\n..World !\n'
197197
198198 s = d"""
199199 --->Hello
200- __World !
201- __ """ # There is no common indentation.
202- print (repr (s)) # '\tHello\n__World!\n__ '
200+ ..World !
201+ .. """ # There is no common indentation.
202+ print (repr (s)) # '\tHello\n..World!\n.. '
203203
204204 # Line continuation with backslash works as usual.
205205 # But you cannot put a backslash right after the opening quotes.
206206 s = d"""
207- __Hello \
208- __World !\
209- __ """
210- print (repr (s)) # 'Hello_World !'
207+ ..Hello \
208+ ..World !\
209+ .. """
210+ print (repr (s)) # 'Hello World !'
211211
212212 s = d""" \
213- __Hello
214- __World
215- __ """ # SyntaxError: d-string must starts with a newline.
213+ ..Hello
214+ ..World
215+ .. """ # SyntaxError: d-string must starts with a newline.
216216
217217 # d-string can be combined with r-string, b-string, f-string, and t-string.
218218 s = dr"""
219- __Hello \
220- __World !\
221- __ """
219+ ..Hello \
220+ ..World !\
221+ .. """
222222 print (repr (s)) # 'Hello\\\nWorld!\\\n'
223223
224224 s = db"""
225- __Hello
226- __World !
227- __ """
225+ ..Hello
226+ ..World !
227+ .. """
228228 print (repr (s)) # b'Hello\nWorld!\n'
229229
230230 s = df"""
231- ____Hello , {"world".title()}!
232- ____ """
233- print (repr (s)) # 'Hello,_World !\n'
231+ ....Hello , {"world".title()}!
232+ .... """
233+ print (repr (s)) # 'Hello,.World !\n'
234234
235235 s = dt"""
236- ____Hello , {"world".title()}!
237- ____ """
236+ ....Hello , {"world".title()}!
237+ .... """
238238 print (type (s)) # <class 'string.templatelib.Template'>
239- print (s.strings) # ('Hello,_ ', '!\n')
239+ print (s.strings) # ('Hello, ', '!\n')
240240 print (s.values) # ('World',)
241241
242242
@@ -413,15 +413,15 @@ newline like below:
413413.. code-block :: python
414414
415415 s = d"""
416- ____Hello
417- ____World !
418- __ """ # "__Hello\n__World !" (no trailing newline)
416+ Hello
417+ World !
418+ """ # " Hello\n World !" (no trailing newline)
419419
420420 s = d"""
421- ____Hello
422- ____World !
421+ Hello
422+ World !
423423
424- __ """ # "__Hello\n__World !\n" (has a trailing newline)
424+ """ # " Hello\n World !\n" (has a trailing newline)
425425
426426 However, including a newline at the end of the last line of a multiline string
427427literal is a very common case, and requiring an empty line at the end would
@@ -444,21 +444,21 @@ you can use workarounds such as line continuation or ``str.rstrip()``.
444444.. code-block :: python
445445
446446 s = d"""
447- ____Hello
448- ____World !"""
447+ Hello
448+ World !"""
449449 assert s == " Hello\n World!"
450450
451451 s = d"""
452- ____Hello
453- ____World !\
454- __ """
455- assert s == " __Hello \n __World !"
452+ Hello
453+ World !\
454+ """
455+ assert s == " Hello \n World !"
456456
457457 s = dr"""
458- ____Hello
459- ____World !
460- __ """ .rstrip()
461- assert s == " __Hello \n __World !"
458+ Hello
459+ World !
460+ """ .rstrip()
461+ assert s == " Hello \n World !"
462462
463463 While these workarounds are not ideal, the drawbacks are considered smaller
464464than the confusion that would result from automatically removing the trailing
0 commit comments