[issue37068] Emit SyntaxWarning for f-strings without expressions ?

Terry J. Reedy report at bugs.python.org
Fri May 31 17:14:40 EDT 2019


Terry J. Reedy <tjreedy at udel.edu> added the comment:

An f-string is equivalent to a format string and call. The exact details are not important.

An field with no value is an error either way.  (I prefer the compile-time exception.)
>>> f'{}a'
SyntaxError: f-string: empty expression not allowed
>>> '{}a'.format()
Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    '{}a'.format()
IndexError: tuple index out of range

>>> 'abc'.format()
'abc'
>>> f'abc'
'abc'

I agree that neither needs a warning.  I actually think the useless call is worse than the unneeded prefix.

SyntaxWarnings are rare.  Invalid escapes are now errors.
>>> '\o'
SyntaxError: invalid escape sequence \o

----------
nosy: +terry.reedy
resolution:  -> rejected
stage:  -> resolved
status: open -> closed
type:  -> enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37068>
_______________________________________


More information about the Python-bugs-list mailing list