-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-132661: Document t-strings and templatelib
#135229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5a8dbfa
09a1e9e
ec44c2b
d8904b6
550aa6d
a20e058
1f30739
d935dd6
1e47362
7b660be
00a535d
fcd74e6
a796f5d
21d337c
d043381
9a0a301
f2e5ca4
8484b81
56ef703
5a8cf1b
127ebc6
73e1222
530cb6d
eaec534
05b5beb
680189a
71ddbf4
1c0ed70
ecc86c3
64c6758
16a995d
7f376d7
9e87880
574c29c
6f0f95a
95df68f
e562c4e
25d9a6f
72b36fe
15dd810
fd38fba
84dbc16
54914fe
7eca01e
687c506
3827427
79169d1
5d7491c
115eaa5
04c2e8d
2da418b
9070840
5af0434
437320d
d69d8e0
ae6f072
6446762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -462,7 +462,7 @@ Glossary | |||||||
core and with user code. | ||||||||
|
||||||||
f-string | ||||||||
String literals prefixed with ``'f'`` or ``'F'`` are commonly called | ||||||||
String literals prefixed with ``f`` or ``F`` are commonly called | ||||||||
"f-strings" which is short for | ||||||||
:ref:`formatted string literals <f-strings>`. See also :pep:`498`. | ||||||||
|
||||||||
|
@@ -1318,7 +1318,7 @@ Glossary | |||||||
See also :term:`borrowed reference`. | ||||||||
|
||||||||
t-string | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
String literals prefixed with ``'t'`` or ``'T'`` are commonly called | ||||||||
String literals prefixed with ``t`` or ``T`` are commonly called | ||||||||
"t-strings" which is short for | ||||||||
:ref:`template string literals <t-strings>`. | ||||||||
|
||||||||
|
davepeck marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||
:mod:`!string.templatelib` --- Templates and Interpolations for t-strings | ||||||||
:mod:`!string.templatelib` --- Templates and interpolations for t-strings | ||||||||
========================================================================= | ||||||||
|
||||||||
.. module:: string.templatelib | ||||||||
|
@@ -11,9 +11,9 @@ | |||||||
|
||||||||
.. seealso:: | ||||||||
|
||||||||
:ref:`T-strings tutorial <tut-t-strings>` | ||||||||
:ref:`Format strings <f-strings>` | ||||||||
:ref:`T-string literal syntax <t-strings>` | ||||||||
* :ref:`T-strings tutorial <tut-t-strings>` | ||||||||
* :ref:`Format strings <f-strings>` | ||||||||
* :ref:`T-string literal syntax <t-strings>` | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
.. _template-strings: | ||||||||
|
@@ -109,6 +109,8 @@ reassigned. | |||||||
|
||||||||
>>> t"".strings | ||||||||
('',) | ||||||||
>>> t"".values | ||||||||
() | ||||||||
>>> t"{'cheese'}".strings | ||||||||
('', '') | ||||||||
>>> t"{'cheese'}".values | ||||||||
|
@@ -191,10 +193,10 @@ reassigned. | |||||||
:param value: The evaluated, in-scope result of the interpolation. | ||||||||
:type value: object | ||||||||
|
||||||||
:param expression: The text of a valid Python expression, or an empty string | ||||||||
:param expression: The text of a valid Python expression, or an empty string. | ||||||||
:type expression: str | ||||||||
|
||||||||
:param conversion: The optional :ref:`conversion <formatstrings>` to be used, one of r, s, and a,. | ||||||||
:param conversion: The optional :ref:`conversion <formatstrings>` to be used, one of r, s, and a. | ||||||||
:type conversion: Literal["a", "r", "s"] | None | ||||||||
|
||||||||
:param format_spec: An optional, arbitrary string used as the :ref:`format specification <formatspec>` to present the value. | ||||||||
|
@@ -229,8 +231,8 @@ reassigned. | |||||||
|
||||||||
.. property:: conversion | ||||||||
|
||||||||
:returns: The conversion to apply to the value, or ``None`` | ||||||||
:rtype: Literal["a", "r", "s"] | None | ||||||||
:returns: The conversion to apply to the value, or ``None``. | ||||||||
:rtype: ``Literal["a", "r", "s"] | None`` | ||||||||
|
||||||||
The :attr:`!Interpolation.conversion` is the optional conversion to apply | ||||||||
to the value: | ||||||||
davepeck marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -561,9 +561,9 @@ escapes are not treated specially. | |||||||||||||
single: f'; formatted string literal | ||||||||||||||
single: f"; formatted string literal | ||||||||||||||
|
||||||||||||||
A string literal with ``'f'`` or ``'F'`` in its prefix is a | ||||||||||||||
:dfn:`formatted string literal`; see :ref:`f-strings`. The ``'f'`` may be | ||||||||||||||
combined with ``'r'``, but not with ``'b'`` or ``'u'``, therefore raw | ||||||||||||||
A string literal with ``f`` or ``F`` in its prefix is a | ||||||||||||||
:dfn:`formatted string literal`; see :ref:`f-strings`. The ``f`` may be | ||||||||||||||
combined with ``r``, but not with ``b`` or ``u``, therefore raw | ||||||||||||||
Comment on lines
+564
to
+566
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated changes; please revert. Also, arguably in lexical analysis we care about the character qua character.
Suggested change
|
||||||||||||||
formatted strings are possible, but formatted bytes literals are not. | ||||||||||||||
|
||||||||||||||
In triple-quoted literals, unescaped newlines and quotes are allowed (and are | ||||||||||||||
|
@@ -756,7 +756,7 @@ f-strings | |||||||||||||
.. versionadded:: 3.6 | ||||||||||||||
|
||||||||||||||
A :dfn:`formatted string literal` or :dfn:`f-string` is a string literal | ||||||||||||||
that is prefixed with ``'f'`` or ``'F'``. These strings may contain | ||||||||||||||
that is prefixed with ``f`` or ``F``. These strings may contain | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likewise
Suggested change
|
||||||||||||||
replacement fields, which are expressions delimited by curly braces ``{}``. | ||||||||||||||
While other string literals always have a constant value, formatted strings | ||||||||||||||
are really expressions evaluated at run time. | ||||||||||||||
|
@@ -922,7 +922,7 @@ t-strings | |||||||||||||
.. versionadded:: 3.14 | ||||||||||||||
|
||||||||||||||
A :dfn:`template string literal` or :dfn:`t-string` is a string literal | ||||||||||||||
that is prefixed with ``'t'`` or ``'T'``. These strings follow the same | ||||||||||||||
that is prefixed with ``t`` or ``T``. These strings follow the same | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the above, I'd keep the quotation marks here, we're in lexical analysis.
Suggested change
|
||||||||||||||
syntax and evaluation rules as :ref:`formatted string literals <f-strings>`, with | ||||||||||||||
the following differences: | ||||||||||||||
|
||||||||||||||
|
@@ -950,9 +950,9 @@ the following differences: | |||||||||||||
:attr:`~string.templatelib.Template.interpolations` attribute will also | ||||||||||||||
contain an ``Interpolation`` instance for the expression. By default, the | ||||||||||||||
:attr:`~string.templatelib.Interpolation.conversion` attribute will be set to | ||||||||||||||
``'r'`` (i.e. :func:`repr`), unless there is a conversion explicitly specified | ||||||||||||||
(in which case it overrides the default) or a format specifier is provided (in | ||||||||||||||
which case, the ``conversion`` defaults to ``None``). | ||||||||||||||
``'r'`` (that is, :func:`repr`), unless there is a conversion explicitly | ||||||||||||||
specified (in which case it overrides the default) or a format specifier is | ||||||||||||||
provided (in which case, the ``conversion`` defaults to ``None``). | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
.. _numbers: | ||||||||||||||
|
davepeck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.