[New-bugs-announce] [issue41045] f-string's "debug" feature is undocumented
Eric V. Smith
report at bugs.python.org
Fri Jun 19 19:53:12 EDT 2020
New submission from Eric V. Smith <eric at trueblade.com>:
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' "
----------
assignee: docs at python
components: Documentation
messages: 371912
nosy: docs at python, eric.smith
priority: normal
severity: normal
stage: needs patch
status: open
title: f-string's "debug" feature is undocumented
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41045>
_______________________________________
More information about the New-bugs-announce
mailing list