Author eric.smith
Recipients docs@python, eric.smith
Date 2020-06-19.23:53:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592610792.76.0.722931750761.issue41045@roundup.psfhosted.org>
In-reply-to
Content
The feature of f-strings using '=' for "debugging" formatting is not documented.

>>> foo = 'bar'
>>> f'{foo=}'
"foo='bar'"


I'm not sure where this should fit in to the documentation, but it needs to be in there somewhere.

Basically the documentation needs to say:

1. The entire string from the opening brace { to the start of the expression appears in the output. This allows things like f'{foo = }' to evaluate to "foo = 'bar'" (notice the extra spaces).

2. If no format spec (like :20) is given, repr() is used on the expression. If a format spec is given, then str() is used on the expression. You can use repr() with a format spec by using the !r conversion, like: 

>>> f'{foo=:20}'
'foo=bar                 '

>>> f'{foo=!r:20}'
"foo='bar'               "
History
Date User Action Args
2020-06-19 23:53:12eric.smithsetrecipients: + eric.smith, docs@python
2020-06-19 23:53:12eric.smithsetmessageid: <1592610792.76.0.722931750761.issue41045@roundup.psfhosted.org>
2020-06-19 23:53:12eric.smithlinkissue41045 messages
2020-06-19 23:53:12eric.smithcreate