Skip to content

gh-85583: Add overview of formatted string literals (f-strings) to str #132689

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented Apr 18, 2025

@python-cla-bot

This comment was marked as resolved.

@bedevere-app bedevere-app bot added awaiting core review docs Documentation in the Doc dir skip news labels Apr 18, 2025
@AA-Turner AA-Turner marked this pull request as draft April 18, 2025 15:01
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Apr 18, 2025
@AA-Turner AA-Turner requested a review from ezio-melotti April 18, 2025 15:41
@AA-Turner AA-Turner changed the title Docs: Add overview of formatted string literals (f-strings) to str gh-85583: Add overview of formatted string literals (f-strings) to str Apr 18, 2025
Copy link
Contributor

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also more links to other pages? e.g. lexical analysis

(Should the title not be "...to stdtypes"?)

@skirpichev skirpichev self-requested a review April 19, 2025 01:24
@AA-Turner
Copy link
Member Author

@skirpichev I'd like to merge this soon, I saw you requested a review. Do you have any comments?

A


.. versionadded:: 3.6
.. versionchanged:: 3.7
The :keyword:`await` and :keyword:`async for` can be used in expressions
Copy link
Contributor

@StanFromIreland StanFromIreland Apr 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The :keyword:`await` and :keyword:`async for` can be used in expressions
:keyword:`await` and :keyword:`async for` can be used in expressions

Either remove it or make it longer, IMO shorter is better.

Many restrictions on expressions within f-strings have been removed.
Notably, nested strings, comments, and backslashes are now permitted.

An :dfn:`f-string` (formally a :dfn:`formatted string literal`) is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
An :dfn:`f-string` (formally a :dfn:`formatted string literal`) is
An :dfn:`f-string` (:dfn:`formatted string literal`) is

Is it more formal? f-string is pretty much an abbreviation.

>>> f'{{x}} is {x}'
'{x} is 42'

Functions can also be used, and :ref:`format specifier <formatstrings>`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Functions can also be used, and :ref:`format specifier <formatstrings>`:
Functions can also be used, and :ref:`format specifiers <formatstrings>`:

Grammar

Comment on lines +2566 to +2567
While debugging it may be helpful to see both the expression and its value,
using the equals sign (``=``) after the expression.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
While debugging it may be helpful to see both the expression and its value,
using the equals sign (``=``) after the expression.
While debugging it may be helpful to see both the expression and its value
by using the equals sign (``=``) after the expression.

using the equals sign (``=``) after the expression.
This preserves spaces within the brackets, and can be used with a converter.
By default, the debugging operator uses the :func:`repr` (``!r``) conversion.
For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the "For example:" every time? Looking at the file it has mixed usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants