From e1d874da267bf9b6fdb2925fbda71a6d0e14845b Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Tue, 14 Jul 2020 23:47:35 +0300 Subject: [PATCH 1/8] Update lexical_analysis.rst This is a trial at closing bpo-41045. --- Doc/reference/lexical_analysis.rst | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index e3a3a88757ed29..f0765f1b1cf1bb 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -659,7 +659,7 @@ for the contents of the string is: .. productionlist:: f_string: (`literal_char` | "{{" | "}}" | `replacement_field`)* - replacement_field: "{" `f_expression` ["!" `conversion`] [":" `format_spec`] "}" + replacement_field: "{" `f_expression` ["="] ["!" `conversion`] [":" `format_spec`] "}" f_expression: (`conditional_expression` | "*" `or_expr`) : ("," `conditional_expression` | "," "*" `or_expr`)* [","] : | `yield_expression` @@ -671,8 +671,9 @@ The parts of the string outside curly braces are treated literally, except that any doubled curly braces ``'{{'`` or ``'}}'`` are replaced with the corresponding single curly brace. A single opening curly bracket ``'{'`` marks a replacement field, which starts with a -Python expression. After the expression, there may be a conversion field, -introduced by an exclamation point ``'!'``. A format specifier may also +Python expression. To display both the expression text and its value after evaluation, +(useful in debugging), an equals ``'='`` may be added after the expression. A conversion field, +introduced by an exclamation point ``'!'`` may follow. A format specifier may also be appended, introduced by a colon ``':'``. A replacement field ends with a closing curly bracket ``'}'``. @@ -690,6 +691,16 @@ left to right. containing an :keyword:`async for` clause were illegal in the expressions in formatted string literals due to a problem with the implementation. +When the equals ``'='`` is provided, the output will have the expression text, the +``'='`` and the evaluated value. Spaces after the opening brace ``'{'``, within the +expression and after the ``'='`` are all retained in the output. By default, the +``'='`` causes the :func:`repr` of the expression to be provided, unless there is a +format specified. When a format is specified it defaults to the :func:`str` of the +expression unless a conversion ``'!r'`` is declared. + +.. versionchanged:: 3.8 + The equals ``'='`` was added in Python 3.8. + If a conversion is specified, the result of evaluating the expression is converted before formatting. Conversion ``'!s'`` calls :func:`str` on the result, ``'!r'`` calls :func:`repr`, and ``'!a'`` calls :func:`ascii`. @@ -724,9 +735,22 @@ Some examples of formatted string literals:: >>> today = datetime(year=2017, month=1, day=27) >>> f"{today:%B %d, %Y}" # using date format specifier 'January 27, 2017' + >>> f"{today=:%B %d, %Y}" # using date format specifier and debugging + 'today=January 27, 2017' >>> number = 1024 >>> f"{number:#0x}" # using integer format specifier '0x400' + >>> foo = "bar" + >>> f"{ foo = }" # preserves whitespace + " foo = 'bar'" + >>> line = "The mill's closed" + >>> f"{line = }" + 'line = "The mill\'s closed"' + >>> f"{line = :20}" + "line = The mill's closed " + >>> f"{line = !r:20}" + 'line = "The mill\'s closed" ' + A consequence of sharing the same syntax as regular string literals is that characters in the replacement fields must not conflict with the From d2a400641c1580b31edb17f8bc306babfbe53101 Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Tue, 14 Jul 2020 23:57:02 +0300 Subject: [PATCH 2/8] Update lexical_analysis.rst --- Doc/reference/lexical_analysis.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index f0765f1b1cf1bb..f70afd0c4b1be7 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -698,7 +698,7 @@ expression and after the ``'='`` are all retained in the output. By default, the format specified. When a format is specified it defaults to the :func:`str` of the expression unless a conversion ``'!r'`` is declared. -.. versionchanged:: 3.8 +.. versionadded:: 3.8 The equals ``'='`` was added in Python 3.8. If a conversion is specified, the result of evaluating the expression From eed3af1c4b407769aaad44dcc8dbe135be673309 Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Mon, 20 Jul 2020 01:19:06 +0300 Subject: [PATCH 3/8] Update lexical_analysis.rst --- Doc/reference/lexical_analysis.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index f70afd0c4b1be7..353ed578010c1e 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -640,6 +640,7 @@ and formatted string literals may be concatenated with plain string literals. single: {} (curly brackets); in formatted string literal single: ! (exclamation); in formatted string literal single: : (colon); in formatted string literal + single: = (equal); for help in debugging using string literals .. _f-strings: Formatted string literals From 477587ec0efe6a10eb84906fcca727558eb3a296 Mon Sep 17 00:00:00 2001 From: amaajemyfren Date: Mon, 27 Jul 2020 23:15:47 +0300 Subject: [PATCH 4/8] Update lexical_analysis.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change "equals" → "equal sign" Limit line length to 80 characters with the exception of productionList --- Doc/reference/lexical_analysis.rst | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 353ed578010c1e..b0107c7f61ec76 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -672,11 +672,11 @@ The parts of the string outside curly braces are treated literally, except that any doubled curly braces ``'{{'`` or ``'}}'`` are replaced with the corresponding single curly brace. A single opening curly bracket ``'{'`` marks a replacement field, which starts with a -Python expression. To display both the expression text and its value after evaluation, -(useful in debugging), an equals ``'='`` may be added after the expression. A conversion field, -introduced by an exclamation point ``'!'`` may follow. A format specifier may also -be appended, introduced by a colon ``':'``. A replacement field ends -with a closing curly bracket ``'}'``. +Python expression. To display both the expression text and its value after +evaluation, (useful in debugging), an equal sign ``'='`` may be added after the +expression. A conversion field, introduced by an exclamation point ``'!'`` may +follow. A format specifier may also be appended, introduced by a colon ``':'``. +A replacement field ends with a closing curly bracket ``'}'``. Expressions in formatted string literals are treated like regular Python expressions surrounded by parentheses, with a few exceptions. @@ -692,15 +692,16 @@ left to right. containing an :keyword:`async for` clause were illegal in the expressions in formatted string literals due to a problem with the implementation. -When the equals ``'='`` is provided, the output will have the expression text, the -``'='`` and the evaluated value. Spaces after the opening brace ``'{'``, within the -expression and after the ``'='`` are all retained in the output. By default, the -``'='`` causes the :func:`repr` of the expression to be provided, unless there is a -format specified. When a format is specified it defaults to the :func:`str` of the -expression unless a conversion ``'!r'`` is declared. +When the equal sign ``'='`` is provided, the output will have the expression +text, the ``'='`` and the evaluated value. Spaces after the opening brace +``'{'``, within the expression and after the ``'='`` are all retained in the +output. By default, the ``'='`` causes the :func:`repr` of the expression to be +provided, unless there is a format specified. When a format is specified it +defaults to the :func:`str` of the expression unless a conversion ``'!r'`` is +declared. .. versionadded:: 3.8 - The equals ``'='`` was added in Python 3.8. + The equal sign ``'='`` was added in Python 3.8. If a conversion is specified, the result of evaluating the expression is converted before formatting. Conversion ``'!s'`` calls :func:`str` on From aa4c12a0568e2754ace66804466e10af0fed87bb Mon Sep 17 00:00:00 2001 From: amaajemyfren Date: Mon, 27 Jul 2020 23:31:24 +0300 Subject: [PATCH 5/8] Modified lexical_analysis.rst Changed the index change = from equal to equals --- Doc/reference/lexical_analysis.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index b0107c7f61ec76..d977aa545d5519 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -640,7 +640,7 @@ and formatted string literals may be concatenated with plain string literals. single: {} (curly brackets); in formatted string literal single: ! (exclamation); in formatted string literal single: : (colon); in formatted string literal - single: = (equal); for help in debugging using string literals + single: = (equals); for help in debugging using string literals .. _f-strings: Formatted string literals From 725cf321f6b097ca61ff6deea16f5588400b0d89 Mon Sep 17 00:00:00 2001 From: amaajemyfren Date: Mon, 27 Jul 2020 23:33:34 +0300 Subject: [PATCH 6/8] Update lexical_analysis.rst Add index entry for symbols --- Doc/reference/lexical_analysis.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index d977aa545d5519..d2cb5efd5cd1eb 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -637,6 +637,7 @@ and formatted string literals may be concatenated with plain string literals. single: string; formatted literal single: string; interpolated literal single: f-string + single: fstring single: {} (curly brackets); in formatted string literal single: ! (exclamation); in formatted string literal single: : (colon); in formatted string literal From dfc5a892a665633e14bbf0e514ca809f05209b7e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2020 20:46:17 +0000 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Documentation/2020-07-27-20-46-17.bpo-41045.GFF6Ul.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2020-07-27-20-46-17.bpo-41045.GFF6Ul.rst diff --git a/Misc/NEWS.d/next/Documentation/2020-07-27-20-46-17.bpo-41045.GFF6Ul.rst b/Misc/NEWS.d/next/Documentation/2020-07-27-20-46-17.bpo-41045.GFF6Ul.rst new file mode 100644 index 00000000000000..dfc9891bb89f27 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2020-07-27-20-46-17.bpo-41045.GFF6Ul.rst @@ -0,0 +1 @@ +Add documentation for debug feature of f-strings. \ No newline at end of file From 69e121151194e2a5dc6ba1abf4817bb1b980c1fa Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Tue, 28 Jul 2020 00:55:35 +0300 Subject: [PATCH 8/8] Update lexical_analysis.rst Remove extra spaces. --- Doc/reference/lexical_analysis.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index d2cb5efd5cd1eb..c65466dcb10cca 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -673,7 +673,7 @@ The parts of the string outside curly braces are treated literally, except that any doubled curly braces ``'{{'`` or ``'}}'`` are replaced with the corresponding single curly brace. A single opening curly bracket ``'{'`` marks a replacement field, which starts with a -Python expression. To display both the expression text and its value after +Python expression. To display both the expression text and its value after evaluation, (useful in debugging), an equal sign ``'='`` may be added after the expression. A conversion field, introduced by an exclamation point ``'!'`` may follow. A format specifier may also be appended, introduced by a colon ``':'``. @@ -753,7 +753,7 @@ Some examples of formatted string literals:: "line = The mill's closed " >>> f"{line = !r:20}" 'line = "The mill\'s closed" ' - + A consequence of sharing the same syntax as regular string literals is that characters in the replacement fields must not conflict with the