Skip to content

Commit fd38fba

Browse files
committed
Take care of all but one of @encukou's feedbacks
1 parent 15dd810 commit fd38fba

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Doc/library/ast.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ Literals
289289
* ``conversion`` is an integer:
290290

291291
* -1: no formatting
292-
* 115: ``!s`` string formatting
293-
* 114: ``!r`` repr formatting
294-
* 97: ``!a`` ASCII formatting
292+
* 115 (``ord('s')``): ``!s`` string formatting
293+
* 114 (``ord('r')``): ``!r`` repr formatting
294+
* 97 (``ord('a')``): ``!a`` ASCII formatting
295295

296296
* ``format_spec`` is a :class:`JoinedStr` node representing the formatting
297297
of the value, or ``None`` if no format was specified. Both

Doc/library/string.templatelib.rst

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ reassigned.
144144
``interpolations`` tuple. It is equivalent to
145145
``tuple(i.value for i in template.interpolations)``.
146146

147-
.. method:: __iter__()
147+
.. describe:: iter(template)
148148

149149
Iterate over the template, yielding each string and
150150
:class:`Interpolation` in order.
@@ -159,7 +159,8 @@ reassigned.
159159
>>> list(t"Hello {name}{name}")
160160
['Hello ', Interpolation('World', 'name', None, ''), Interpolation('World', 'name', None, '')]
161161

162-
.. method:: __add__(other)
162+
.. describe:: template + other
163+
.. describe:: template += other
163164

164165
Concatenate this template with another, returning a new
165166
:class:`!Template` instance:
@@ -197,7 +198,7 @@ reassigned.
197198
:type expression: str
198199

199200
:param conversion: The optional :ref:`conversion <formatstrings>` to be used, one of r, s, and a.
200-
:type conversion: Literal["a", "r", "s"] | None
201+
:type conversion: ``Literal["a", "r", "s"] | None``
201202

202203
:param format_spec: An optional, arbitrary string used as the :ref:`format specification <formatspec>` to present the value.
203204
:type format_spec: str
@@ -207,15 +208,15 @@ reassigned.
207208
:class:`!Interpolation` instances are shallow immutable: their attributes cannot be
208209
reassigned.
209210

210-
.. property:: value
211+
.. attribute:: value
211212

212213
:returns: The evaluated value of the interpolation.
213214
:rtype: object
214215

215216
>>> t"{1 + 2}".interpolations[0].value
216217
3
217218

218-
.. property:: expression
219+
.. attribute:: expression
219220

220221
:returns: The text of a valid Python expression, or an empty string.
221222
:rtype: str
@@ -229,7 +230,7 @@ reassigned.
229230
>>> t"{1 + 2}".interpolations[0].expression
230231
'1 + 2'
231232

232-
.. property:: conversion
233+
.. attribute:: conversion
233234

234235
:returns: The conversion to apply to the value, or ``None``.
235236
:rtype: ``Literal["a", "r", "s"] | None``
@@ -247,7 +248,7 @@ reassigned.
247248
:class:`!Template` will decide how to interpret and whether to apply
248249
the :attr:`!Interpolation.conversion`.
249250

250-
.. property:: format_spec
251+
.. attribute:: format_spec
251252

252253
:returns: The format specification to apply to the value.
253254
:rtype: str
@@ -269,10 +270,13 @@ reassigned.
269270
do not necessarily conform to the rules of Python's :func:`format`
270271
protocol.
271272

272-
.. property:: __match_args__
273-
274-
:returns: A tuple of the attributes to use for structural pattern matching.
275-
276-
The tuple returned is ``('value', 'expression', 'conversion', 'format_spec')``.
277-
This allows for :ref:`pattern matching <match>` on :class:`!Interpolation` instances.
273+
Interpolations support pattern matching, allowing you to match against
274+
their attributes with the :ref:`match statement <match>`:
278275

276+
>>> from string.templatelib import Interpolation
277+
>>> interpolation = Interpolation(3.0, "1 + 2", None, ".2f")
278+
>>> match interpolation:
279+
... case Interpolation(value, expression, conversion, format_spec):
280+
... print(value, expression, conversion, format_spec)
281+
...
282+
3.0 1 + 2 None .2f

0 commit comments

Comments
 (0)