This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PEP 498: Minor mistakes/outdateness
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Arfrever, eric.smith, martin.panter, python-dev
Priority: normal Keywords:

Created on 2015-09-21 19:57 by Arfrever, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg251250 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2015-09-21 19:57
"""
For example, this code:

 f'abc{expr1:spec1}{expr2!r:spec2}def{expr3:!s}ghi'

Might be be evaluated as:

 'abc' + format(expr1, spec1) + format(repr(expr2)) + 'def' + format(str(expr3)) + 'ghi'
"""

format(repr(expr2)) should be format(repr(expr2), spec2)



"""
>>> f'x={x'
  File "<stdin>", line 1
SyntaxError: missing '}' in format string expression
"""

Actually implemented exception message is:
SyntaxError: f-string: expecting '}'



"""
>>> f'x={!x}'
  File "<fstring>", line 1
    !x
    ^
SyntaxError: invalid syntax
"""

Actually implemented exception message is:
SyntaxError: f-string: invalid conversion character: expected 's', 'r', or 'a'
msg251261 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-21 21:16
New changeset 831276834e4b by Eric V. Smith in branch 'default':
Partial fix for issue 25206: Fixed format() call.
https://hg.python.org/peps/rev/831276834e4b
msg251274 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-09-21 22:45
Also in the first example, the colon (format specifier) and exclamation mark (conversion) are in the wrong order. It should either be

f"{expr3:!s}" → format(expr3, "!s")

or

f"{expr3!s:}" → format(str(expr3), "")
msg251325 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-22 15:27
New changeset df19ba9217e4 by Eric V. Smith in branch 'default':
More on issue 25206: typo.
https://hg.python.org/peps/rev/df19ba9217e4
msg251326 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-09-22 15:34
Thanks for the feedback.

On the 
f"{expr3!s}" → format(str(expr3))
issue, I'm trying to show the 1 argument version of format (which is what the code generator actually calls). Although I realize that's not a great example, since the string conversion is implicit in format(). Maybe I'll have the !r example be the 1 argument format() call.

I'll fix the exceptions, eventually. But I don't want the PEP to become a exact specification of what the exception text will actually be.

On this one:
f'x={!x}'
I'll probably change it to be an error with the empty expression, not with the invalid conversion character.
msg251519 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-24 13:01
New changeset 7e32da8da58e by Eric V. Smith in branch 'default':
Issue 25206: fix f-string exceptions to match the code.
https://hg.python.org/peps/rev/7e32da8da58e
History
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69393
2015-09-24 13:01:44eric.smithsetstatus: open -> closed
resolution: fixed
stage: resolved
2015-09-24 13:01:18python-devsetmessages: + msg251519
2015-09-22 15:34:10eric.smithsetmessages: + msg251326
2015-09-22 15:27:54python-devsetmessages: + msg251325
2015-09-21 22:45:47martin.pantersetnosy: + martin.panter
messages: + msg251274
2015-09-21 21:16:35python-devsetnosy: + python-dev
messages: + msg251261
2015-09-21 19:57:01Arfrevercreate