You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: peps/pep-0822.rst
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ Example (spaces are visualized as ``_``):
32
32
____"""
33
33
34
34
The closing triple quotes control how much indentation would be removed.
35
-
In the above example, the returned string will contain three lines
35
+
In the above example, the returned string will contain three lines:
36
36
37
37
* ``"____<p>\n"`` (four leading spaces)
38
38
* ``"______Hello, World!\n"`` (six leading spaces)
@@ -54,7 +54,7 @@ All of these options have drawbacks in terms of code readability and maintainabi
54
54
* Left-aligned multiline strings look awkward and tend to be avoided.
55
55
In practice, many places including Python's own test code choose other methods.
56
56
* Concatenated single-line string literals are more verbose and harder to maintain.
57
-
* ``textwrap.dedent()`` is implemented in Python so it require some runtime overhead.
57
+
* ``textwrap.dedent()`` is implemented in Python so it requires some runtime overhead.
58
58
It cannot be used in hot paths where performance is critical.
59
59
60
60
This PEP aims to provide a built-in syntax for dedented multiline strings that
@@ -80,7 +80,7 @@ However, this approach has several drawbacks:
80
80
they cannot be dedented.
81
81
* f-strings may interpolate expressions as multiline string without indent.
82
82
In such case, f-string + ``str.dedent()`` cannot dedent the whole string.
83
-
* t-strings do not create str objects, so they cannot use the ``str.dedent()`` method.
83
+
* t-strings do not create ``str`` objects, so they cannot use the ``str.dedent()`` method.
84
84
While adding a ``dedent()`` method to ``string.templatelib.Template`` is an option,
85
85
it would lead to inconsistency since t-strings and f-strings are very similar but
86
86
would have different behaviors regarding dedentation.
@@ -106,10 +106,10 @@ This newline is not included in the resulting string.
106
106
107
107
The amount of indentation to be removed is determined by the whitespace
108
108
(``' '`` or ``'\t'``) preceding the closing triple quotes.
109
-
Mixing spaces and tabs in indentation raises a TabError, similar to Python's
109
+
Mixing spaces and tabs in indentation raises a ``TabError``, similar to Python's
110
110
own indentation rules.
111
111
112
-
The dedentation process removes the determined amount of leading whitespace from each line in the string.
112
+
The dedentation process removes the determined amount of leading whitespace from every line in the string.
113
113
Lines that are shorter than the determined indentation become just an empty line (e.g. ``"\n"``).
114
114
Otherwise, if the line does not start with the determined indentation,
115
115
Python raises an ``IndentationError``.
@@ -122,7 +122,7 @@ Examples:
122
122
123
123
.. code-block:: python
124
124
125
-
#whiltespace is shown as _ and TAB is shown as ---> for clarity.
125
+
#Whitespace is shown as _ and tab is shown as ---> for clarity.
126
126
# Error messages are just for explanation. Actual messages may differ.
127
127
128
128
s = d""# SyntaxError: d-string must be a multiline string
@@ -166,7 +166,7 @@ Examples:
166
166
s = d"""
167
167
--->--->__Hello
168
168
--->--->__World!
169
-
--->--->"""#TAB is allowed as indentation.
169
+
--->--->"""#Tab is allowed as indentation.
170
170
# Spaces are just in the string, not indentation to be removed.
171
171
print(repr(s)) # '__Hello\n__World!\n'
172
172
@@ -217,10 +217,10 @@ providing a link to the d-string section in the language reference or the releva
217
217
Other Languages having Similar Features
218
218
========================================
219
219
220
-
Java 15 introduced a feature called `Text Blocks<https://openjdk.org/jeps/378>`__.
220
+
Java 15 introduced a feature called `text blocks<https://openjdk.org/jeps/378>`__.
221
221
Since Java had not used triple qutes before, they introduced triple quotes for multiline string literals with automatic indent removal.
222
222
223
-
C# 11 also introduced a similar feature called `Raw String Literals<https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-11.0/raw-string-literal>`__.
223
+
C# 11 also introduced a similar feature called `raw string literals<https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-11.0/raw-string-literal>`__.
224
224
225
225
`Julia <https://docs.julialang.org/en/v1/manual/strings/#Triple-Quoted-String-Literals>`__ and
0 commit comments