From 8f15283671a76c7c44b6de475cb3079ef247f777 Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Mon, 20 Jul 2020 01:01:22 +0300 Subject: [PATCH 01/11] Update stdtypes.rst First attempt at documenting f-strings within the Python Docs and not in reference documents. --- Doc/library/stdtypes.rst | 174 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 2082b849fd05b0..fbf69162a5992e 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2392,6 +2392,180 @@ that ``'\0'`` is the end of the string. .. index:: single: buffer protocol; binary sequence types + +.. index:: + single: formatted string literal + single: interpolated string literal + single: string; formatted literal + single: string; interpolated literal + single: f-string + single: {} (curly brackets); in formatted string literal + single: ! (exclamation); in formatted string literal + single: : (colon); in formatted string literal + single: = (equal); in debug string literal +.. _f-string-formated-string-literal: + +``f-string``Formatted String Literal +------------------------------------ +.. 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 +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. + +This adds flexibility to how strings can be formatted:: + + >>> name = "Fred" + >>> f"He said his name is {name!r}." + "He said his name is 'Fred'." + +The above is an example and will become clear as you read below. + +Everything outside the curly braces is treated as literally with the exception +of double braces which are treated as one brace:: + + >>> f"This is a string" + 'This is a string.' + >>> f'{{' + '{' + >>> F"{{" + '}' + >>> F'{{ }}' + '{ }' + +A single opening curly bracket, ``'{'``, marks a replacement field that starts with +a python expression.:: + + >>> f"4 * 3 is {4 * 3}" + '4 * 3 is 12' + +The above is quite contrived and a more useful use in code could be:: + + >>> a = 4 + >>> b = 3 + >>> f"The product of {a} and {b} is {a * b}" + 'The product of 4 and 3 is 12' + +Or more simply:: + + >>> a = 4 + >>> b = 3 + >>> f"The product is {a * b}" + 'The product is 12' + +Methods can also be used:: + + >>> string = "hello, world!" + >>> f"{string.title()}" + 'Hello, World!' + >>> def make_title(input): + ... return input.title() + ... + >>> f"{make_title(string)}" + 'Hello, World!' + +Any variable that can be presented as a string can be used with f-strings:: + + >>> import datetime + >>> now = datetime.datetime.now() + >>> f"{now}" + '2020-07-19 23:39:01.199675' + +Note that this is the :func:`str` format of a :mod:`datetime`. If you want to show the +:func:`repr` format you use a conversion. There are three conversions beginning with the +``'!'`` (exclamation) mark: + ++------------+---------------+ +| Conversion | Meaning | ++============+===============+ +| ``'!r'`` | :func:`repr` | ++------------+---------------+ +| ``'!s'`` | :func:`str` | ++------------+---------------+ +| ``'!a'`` | :func:`ascii` | ++------------+---------------+ + +In our example of the datetime that becomes:: + + >>> f"{now!r}" + 'datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + >>> f"{now!a}" + 'datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + +While debugging it may be important to see both the expression and its value. +This can be shown by adding the ``'='`` (equal) as part of the replacement expression.:: + + >>> f"{now=}" + 'now=datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + >>> f"{ now = }" # Note the addition of spaces + ' now = datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + +Note that when using the debugging operator, any additional spaces will be left intact in the output. +Also note that by default ``'='`` displays the :func:`repr` of the expression. It is possible to show +the :func:`str` by appending a converter:: + + >>> f"{now=!s}" + 'now=2020-07-19 23:39:01.199675' + >>> f"{ now = !a}" # Note the additional spaces + ' now = datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + +Once the output has been evaluated it can then be formatted using the :func:`format` protocol. +Formatting instructions are appended preceeded by the ``':'`` (colon). + +:: + + >>> f"{now:%B %d, %Y}" + 'July 19, 2020' + +The format specifier is passed to the :meth:`__format__` method of the expression or conversion result. +An empty string is passed when the format specifier is omitted. The formatted result is then included +in the final value of the whole string. + +:: + + >>> width = 10 + >>> precision = 4 + >>> import decimal + >>> value = decimal.Decimal("12.34567") + >>> f"result: {value:{width}.{precision}}" + 'result: 12.35' + +Formatted string literals cannot be used as docstrings, even if they do not +include expressions. + +:: + + >>> def foo(): + ... f"Not a docstring" + ... + >>> foo.__doc__ is None + True + +A consequence of sharing the same syntax as regular string literals is +that characters in the replacement fields must not conflict with the +quoting used in the outer formatted string literal:: + + f"abc {a["x"]} def" # error: outer string literal ended prematurely + f"abc {a['x']} def" # workaround: use different quoting + +Backslashes are not allowed in format expressions and will raise +an error:: + + f"newline: {ord('\n')}" # raises SyntaxError + +To include a value in which a backslash escape is required, create +a temporary variable. + +:: + + >>> newline = ord('\n') + >>> f"newline: {newline}" + 'newline: 10' + + + .. _binaryseq: Binary Sequence Types --- :class:`bytes`, :class:`bytearray`, :class:`memoryview` From afa1a8a634d7ec121ceaafedf9193edf5b1f4f11 Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Mon, 20 Jul 2020 01:56:26 +0300 Subject: [PATCH 02/11] Update stdtypes.rst --- Doc/library/stdtypes.rst | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index fbf69162a5992e..594bd959cab489 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2494,8 +2494,10 @@ In our example of the datetime that becomes:: >>> f"{now!a}" 'datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' -While debugging it may be important to see both the expression and its value. -This can be shown by adding the ``'='`` (equal) as part of the replacement expression.:: +While debugging it may be helpful to see both the expression and its value. +This can be shown by appending the ``'='`` (equal) after the Python expression. + +:: >>> f"{now=}" 'now=datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' @@ -2512,7 +2514,7 @@ the :func:`str` by appending a converter:: ' now = datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' Once the output has been evaluated it can then be formatted using the :func:`format` protocol. -Formatting instructions are appended preceeded by the ``':'`` (colon). +Formatting instructions are appended preceeded by a ``':'`` (colon). :: @@ -2532,6 +2534,20 @@ in the final value of the whole string. >>> f"result: {value:{width}.{precision}}" 'result: 12.35' +When a format specifier is given together with the ``'='`` useful in debuging, the expressions' :func:`str` +conversion is used by default. Conversion can be used to show the :func:`repr` form. + +:: + + >>> f"{value}" + '12.34567' + >>> f"{value=}" + "value=Decimal('12.34567')" + >>> f"{value=:20}" + 'value= 12.34567' + >>> f"{value=!r:20}" + "value=Decimal('12.34567') " + Formatted string literals cannot be used as docstrings, even if they do not include expressions. From 802d2abb441cb4d7edb5f15e5206de6668db6e91 Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Mon, 20 Jul 2020 02:06:18 +0300 Subject: [PATCH 03/11] Update stdtypes.rst --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 594bd959cab489..36422d7d0c5351 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2405,8 +2405,8 @@ that ``'\0'`` is the end of the string. single: = (equal); in debug string literal .. _f-string-formated-string-literal: -``f-string``Formatted String Literal ------------------------------------- +``f-string``-Formatted String Literal +------------------------------------- .. versionadded:: 3.6 A :dfn:`formatted string literal` or :dfn:`f-string` is a string literal From c6d544f942f228838131d6de7fa500f4aae606fb Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Mon, 20 Jul 2020 02:58:00 +0300 Subject: [PATCH 04/11] Update stdtypes.rst --- Doc/library/stdtypes.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 36422d7d0c5351..63aa9de136e3e8 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2420,7 +2420,7 @@ This adds flexibility to how strings can be formatted:: >>> name = "Fred" >>> f"He said his name is {name!r}." "He said his name is 'Fred'." - + The above is an example and will become clear as you read below. Everything outside the curly braces is treated as literally with the exception @@ -2434,27 +2434,27 @@ of double braces which are treated as one brace:: '}' >>> F'{{ }}' '{ }' - + A single opening curly bracket, ``'{'``, marks a replacement field that starts with a python expression.:: >>> f"4 * 3 is {4 * 3}" '4 * 3 is 12' - + The above is quite contrived and a more useful use in code could be:: >>> a = 4 >>> b = 3 >>> f"The product of {a} and {b} is {a * b}" 'The product of 4 and 3 is 12' - + Or more simply:: >>> a = 4 >>> b = 3 >>> f"The product is {a * b}" 'The product is 12' - + Methods can also be used:: >>> string = "hello, world!" @@ -2465,14 +2465,14 @@ Methods can also be used:: ... >>> f"{make_title(string)}" 'Hello, World!' - + Any variable that can be presented as a string can be used with f-strings:: >>> import datetime >>> now = datetime.datetime.now() >>> f"{now}" '2020-07-19 23:39:01.199675' - + Note that this is the :func:`str` format of a :mod:`datetime`. If you want to show the :func:`repr` format you use a conversion. There are three conversions beginning with the ``'!'`` (exclamation) mark: @@ -2493,7 +2493,7 @@ In our example of the datetime that becomes:: 'datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' >>> f"{now!a}" 'datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' - + While debugging it may be helpful to see both the expression and its value. This can be shown by appending the ``'='`` (equal) after the Python expression. @@ -2503,7 +2503,7 @@ This can be shown by appending the ``'='`` (equal) after the Python expression. 'now=datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' >>> f"{ now = }" # Note the addition of spaces ' now = datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' - + Note that when using the debugging operator, any additional spaces will be left intact in the output. Also note that by default ``'='`` displays the :func:`repr` of the expression. It is possible to show the :func:`str` by appending a converter:: @@ -2520,7 +2520,7 @@ Formatting instructions are appended preceeded by a ``':'`` (colon). >>> f"{now:%B %d, %Y}" 'July 19, 2020' - + The format specifier is passed to the :meth:`__format__` method of the expression or conversion result. An empty string is passed when the format specifier is omitted. The formatted result is then included in the final value of the whole string. From 1102da3e59fed2f49c8450ef4c1fb2096d1db495 Mon Sep 17 00:00:00 2001 From: amaajemyfren Date: Tue, 28 Jul 2020 07:54:23 +0300 Subject: [PATCH 05/11] issue 41411 Improve and consolidate f-strings docs Added intermediate description of f-strings in stdtypes documentation. --- Doc/library/stdtypes.rst | 174 +++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 91 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 63aa9de136e3e8..1230345381ebae 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2399,83 +2399,71 @@ that ``'\0'`` is the end of the string. 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 - single: = (equal); in debug string literal + single: = (equals); in debug string literal .. _f-string-formated-string-literal: ``f-string``-Formatted String Literal ------------------------------------- .. 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 -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. +A :dfn:`formatted string literal` or :dfn:`f-string` is a string literal that +is prefixed with ``f`` or ``F``. These strings may contain replacement +fields, which are expressions delimited by curly braces ``{}``. While other +string literals always have a constant value, formatted strings are expressions +evaluated at run time.:: -This adds flexibility to how strings can be formatted:: + >>> F"This is an f-string" + 'This is an f-string' + >>> f"This is also an f-string" + 'This is also an f-string' - >>> name = "Fred" - >>> f"He said his name is {name!r}." - "He said his name is 'Fred'." - -The above is an example and will become clear as you read below. +It is also possible to have a multi line string.:: -Everything outside the curly braces is treated as literally with the exception -of double braces which are treated as one brace:: + >>> f'''This is a string + ... on two lines''' + 'This is a string\non two lines' - >>> f"This is a string" - 'This is a string.' - >>> f'{{' - '{' - >>> F"{{" - '}' - >>> F'{{ }}' - '{ }' - -A single opening curly bracket, ``'{'``, marks a replacement field that starts with +A single opening curly bracket, ``'{'``, marks a replacement field that contains a python expression.:: - >>> f"4 * 3 is {4 * 3}" - '4 * 3 is 12' + >>> name = "Fred" + >>> f"He said his name is {name}" + 'He said his name is Fred' -The above is quite contrived and a more useful use in code could be:: +Everything outside the braces is treated as a literal:: >>> a = 4 >>> b = 3 >>> f"The product of {a} and {b} is {a * b}" 'The product of 4 and 3 is 12' -Or more simply:: +If you want to include a literal ``{`` or ``}``, you can double the curly +brackets to escape them:: - >>> a = 4 - >>> b = 3 - >>> f"The product is {a * b}" - 'The product is 12' + >>> f'{{a}} is {a}' + '{a} is 4' -Methods can also be used:: +Functions can also be used.:: - >>> string = "hello, world!" - >>> f"{string.title()}" - 'Hello, World!' - >>> def make_title(input): - ... return input.title() - ... - >>> f"{make_title(string)}" - 'Hello, World!' + >>> s = "Python" + >>> f"The string {s.upper()} contains {len(s)} characters." + 'The string PYTHON contains 6 characters.' -Any variable that can be presented as a string can be used with f-strings:: +By default the :func:`str` format of a variable is presented when using +f-strings:: >>> import datetime >>> now = datetime.datetime.now() >>> f"{now}" - '2020-07-19 23:39:01.199675' + '2020-07-28 04:33:08.629606' -Note that this is the :func:`str` format of a :mod:`datetime`. If you want to show the -:func:`repr` format you use a conversion. There are three conversions beginning with the -``'!'`` (exclamation) mark: +Note that this is the :func:`str` format of a :mod:`datetime`. To show a +different format you use a conversion. There are three conversions beginning +with the ``'!'`` (exclamation) mark. +------------+---------------+ | Conversion | Meaning | @@ -2487,60 +2475,65 @@ Note that this is the :func:`str` format of a :mod:`datetime`. If you want to sh | ``'!a'`` | :func:`ascii` | +------------+---------------+ -In our example of the datetime that becomes:: +:: >>> f"{now!r}" - 'datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' - >>> f"{now!a}" - 'datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + 'datetime.datetime(2020, 7, 28, 4, 33, 8, 629606)' + >>> hello = "你好" + >>> f"The ASCII version of {hello!r} is {hello!a}." + "The ASCII version of '你好' is '\\u4f60\\u597d'." + +While debugging it may be helpful to see both the expression and its value.:: + + >>> f"now={now}" + 'now=2020-07-28 04:33:08.629606' -While debugging it may be helpful to see both the expression and its value. -This can be shown by appending the ``'='`` (equal) after the Python expression. +The new way to do this is to use the equal sign ``=`` after the expression. + +.. versionadded:: 3.8 :: - >>> f"{now=}" - 'now=datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' - >>> f"{ now = }" # Note the addition of spaces - ' now = datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + >>> f"{now = }" # spaces within braces are maintained. + 'now = datetime.datetime(2020, 7, 28, 4, 33, 8, 629606)' + -Note that when using the debugging operator, any additional spaces will be left intact in the output. -Also note that by default ``'='`` displays the :func:`repr` of the expression. It is possible to show -the :func:`str` by appending a converter:: +When used by its own, the debugging operator ``=``, outputs the :func:`repr` of +the expression. A change this a converter is used:: >>> f"{now=!s}" - 'now=2020-07-19 23:39:01.199675' - >>> f"{ now = !a}" # Note the additional spaces - ' now = datetime.datetime(2020, 7, 19, 23, 39, 1, 199675)' + 'now=2020-07-28 04:33:08.629606' -Once the output has been evaluated it can then be formatted using the :func:`format` protocol. -Formatting instructions are appended preceeded by a ``':'`` (colon). +Once the output has been evaluated it can then be formatted using a formatting +specifier that is appended preceeded by a ``':'`` (colon). -:: +The format specifier is passed to the :meth:`__format__` method of the +expression or conversion result. An empty string is passed when the format +specifier is omitted. The formatted result is then returned as the final value +of the whole string. + +As an example for :mod:`datetime` we use format specifiers from +:ref:`strftime-strptime-behavior` which would give us:: >>> f"{now:%B %d, %Y}" - 'July 19, 2020' + 'July 28, 2020' -The format specifier is passed to the :meth:`__format__` method of the expression or conversion result. -An empty string is passed when the format specifier is omitted. The formatted result is then included -in the final value of the whole string. +Most built-in types will comply with the :ref:`formatspec`.:: -:: + >>> num = 12.3456 + >>> f"{num:20}" + ' 12.3456' + >>> f"{num:<20}" + '12.3456 ' + >>> f"{num:e}" + '1.234560e+01' + +When a format specifier is given together with the equal sign ``'='`` the +default conversion for the expressions' is :func:`str`. Conversion can be used +to show the :func:`repr` form.:: - >>> width = 10 - >>> precision = 4 >>> import decimal >>> value = decimal.Decimal("12.34567") - >>> f"result: {value:{width}.{precision}}" - 'result: 12.35' - -When a format specifier is given together with the ``'='`` useful in debuging, the expressions' :func:`str` -conversion is used by default. Conversion can be used to show the :func:`repr` form. - -:: - - >>> f"{value}" - '12.34567' >>> f"{value=}" "value=Decimal('12.34567')" >>> f"{value=:20}" @@ -2549,15 +2542,13 @@ conversion is used by default. Conversion can be used to show the :func:`repr` f "value=Decimal('12.34567') " Formatted string literals cannot be used as docstrings, even if they do not -include expressions. - -:: +include expressions.:: >>> def foo(): ... f"Not a docstring" ... - >>> foo.__doc__ is None - True + >>> print(foo.__doc__) + None A consequence of sharing the same syntax as regular string literals is that characters in the replacement fields must not conflict with the @@ -2569,12 +2560,13 @@ quoting used in the outer formatted string literal:: Backslashes are not allowed in format expressions and will raise an error:: - f"newline: {ord('\n')}" # raises SyntaxError + >>> f'{ord("\n")}' + File "", line 1 + f'{ord("\n")}' + SyntaxError: f-string expression part cannot include a backslash To include a value in which a backslash escape is required, create -a temporary variable. - -:: +a temporary variable.:: >>> newline = ord('\n') >>> f"newline: {newline}" From a37a88839beeda3158c0fcaaaa2bfcc67284a81c Mon Sep 17 00:00:00 2001 From: amaajemyfren Date: Tue, 28 Jul 2020 08:56:15 +0300 Subject: [PATCH 06/11] bpo-41411 Improve and consolidate f-string Clean up of small errors. --- Doc/library/stdtypes.rst | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 1230345381ebae..0653119c6053d1 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2499,7 +2499,7 @@ The new way to do this is to use the equal sign ``=`` after the expression. When used by its own, the debugging operator ``=``, outputs the :func:`repr` of -the expression. A change this a converter is used:: +the expression. A converter can be used to change it:: >>> f"{now=!s}" 'now=2020-07-28 04:33:08.629606' @@ -2512,13 +2512,13 @@ expression or conversion result. An empty string is passed when the format specifier is omitted. The formatted result is then returned as the final value of the whole string. -As an example for :mod:`datetime` we use format specifiers from -:ref:`strftime-strptime-behavior` which would give us:: +As an example for :mod:`datetime` we could use format specifiers described in +:ref:`strftime-strptime-behavior`:: >>> f"{now:%B %d, %Y}" 'July 28, 2020' -Most built-in types will comply with the :ref:`formatspec`.:: +Most built-in types will comply with the :ref:`formatspec`:: >>> num = 12.3456 >>> f"{num:20}" @@ -2530,7 +2530,7 @@ Most built-in types will comply with the :ref:`formatspec`.:: When a format specifier is given together with the equal sign ``'='`` the default conversion for the expressions' is :func:`str`. Conversion can be used -to show the :func:`repr` form.:: +to show the :func:`repr` form:: >>> import decimal >>> value = decimal.Decimal("12.34567") @@ -2554,8 +2554,15 @@ A consequence of sharing the same syntax as regular string literals is that characters in the replacement fields must not conflict with the quoting used in the outer formatted string literal:: - f"abc {a["x"]} def" # error: outer string literal ended prematurely - f"abc {a['x']} def" # workaround: use different quoting + >>> a = {"Terry":"Jones", "John":"Cleese", "x":"Gilliam", "Eric":"Idle"} + >>> f"abc {a["x"]} def" + File "", line 1 + f"abc {a["x"]} def" + ^ + SyntaxError: f-string: unmatched '[' + + >>> f"abc {a['x']} def" # workaround: use different quoting + 'abc Gilliam def' Backslashes are not allowed in format expressions and will raise an error:: From 8c004d173c5e0300fc04aeed5218f29b98a10fd5 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 28 Jul 2020 06:00:42 +0000 Subject: [PATCH 07/11] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Documentation/2020-07-28-06-00-41.bpo-41411.gB5Ty8.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2020-07-28-06-00-41.bpo-41411.gB5Ty8.rst diff --git a/Misc/NEWS.d/next/Documentation/2020-07-28-06-00-41.bpo-41411.gB5Ty8.rst b/Misc/NEWS.d/next/Documentation/2020-07-28-06-00-41.bpo-41411.gB5Ty8.rst new file mode 100644 index 00000000000000..d700fbcd795188 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2020-07-28-06-00-41.bpo-41411.gB5Ty8.rst @@ -0,0 +1 @@ +Intermediate documentation for f-strings added to /Doc/Lib/stdtypes.rst \ No newline at end of file From ab803e20ccba61af1d58eb0a7a6e75dd93858f22 Mon Sep 17 00:00:00 2001 From: amaajemyfren Date: Tue, 28 Jul 2020 09:07:36 +0300 Subject: [PATCH 08/11] bpo-41411 debug to remove trailing white space --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 0653119c6053d1..d13723b5fb3f6d 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2555,7 +2555,7 @@ that characters in the replacement fields must not conflict with the quoting used in the outer formatted string literal:: >>> a = {"Terry":"Jones", "John":"Cleese", "x":"Gilliam", "Eric":"Idle"} - >>> f"abc {a["x"]} def" + >>> f"abc {a["x"]} def" File "", line 1 f"abc {a["x"]} def" ^ From 729d3d4050924cff3799e2ad2c9d9c18e37ef2d4 Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Thu, 6 Aug 2020 07:17:30 +0300 Subject: [PATCH 09/11] Update Doc/library/stdtypes.rst Change the format of table to simplified form. Co-authored-by: Ezio Melotti --- Doc/library/stdtypes.rst | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index d13723b5fb3f6d..ac84eda77f2976 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2465,15 +2465,13 @@ Note that this is the :func:`str` format of a :mod:`datetime`. To show a different format you use a conversion. There are three conversions beginning with the ``'!'`` (exclamation) mark. -+------------+---------------+ -| Conversion | Meaning | -+============+===============+ -| ``'!r'`` | :func:`repr` | -+------------+---------------+ -| ``'!s'`` | :func:`str` | -+------------+---------------+ -| ``'!a'`` | :func:`ascii` | -+------------+---------------+ +============ =============== + Conversion Meaning +============ =============== + ``!r`` :func:`repr` + ``!s`` :func:`str` + ``!a`` :func:`ascii` +============ =============== :: From 93dc2a992762137a0662f994ccad47f19d931c4c Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Thu, 6 Aug 2020 07:22:03 +0300 Subject: [PATCH 10/11] Modify f-string example to start with small "f" --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ac84eda77f2976..7ff049933d6e41 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2416,9 +2416,9 @@ fields, which are expressions delimited by curly braces ``{}``. While other string literals always have a constant value, formatted strings are expressions evaluated at run time.:: - >>> F"This is an f-string" + >>> f"This is an f-string" 'This is an f-string' - >>> f"This is also an f-string" + >>> F"This is also an f-string" 'This is also an f-string' It is also possible to have a multi line string.:: From 876b580368ae0e51461d0608e1715d2a29b3606a Mon Sep 17 00:00:00 2001 From: amaajemyfren <32741226+amaajemyfren@users.noreply.github.com> Date: Thu, 6 Aug 2020 07:30:09 +0300 Subject: [PATCH 11/11] Remove extra white spaces in stdtypes.rst --- Doc/library/stdtypes.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 7ff049933d6e41..057ba057784b47 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2465,12 +2465,12 @@ Note that this is the :func:`str` format of a :mod:`datetime`. To show a different format you use a conversion. There are three conversions beginning with the ``'!'`` (exclamation) mark. -============ =============== - Conversion Meaning ============ =============== - ``!r`` :func:`repr` - ``!s`` :func:`str` - ``!a`` :func:`ascii` + Conversion Meaning +============ =============== + ``!r`` :func:`repr` + ``!s`` :func:`str` + ``!a`` :func:`ascii` ============ =============== ::