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

2019-06-05 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Adding my agreement that this is a feature, not a bug.

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-05-31 Thread Terry J. Reedy


Terry J. Reedy  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 "", line 1, in 
'{}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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-05-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I do not think that all uses of f-strings without expression are errors. 
Therefore it would be better to left this on linters. Linters are optional and 
usually are flexible in configuring what warnings and in what part of the code 
should be emitted.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-05-27 Thread Eric V. Smith


Eric V. Smith  added the comment:

I think this would be better suited for a linter.

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2019-05-27 Thread Matthias Bussonnier

New submission from Matthias Bussonnier :

Or more precisely I suggest to emit a SyntaxWarning for JoinedStr where no 
f-string members has an expression. 

There seem to be a couple of case where f-strings without expressions may 
indicate
that the programmer may have made a mistake; though there are also a number of
case where f-string w/o expressions are legitimate; I believe we should be able
to emit a SyntaxWarning in case where `f` are really unnecessary or might be a
mistakes.

First case where f-string w/o expressions are legitimate: multiline joined 
string,
to make sure each line is aligned. Example from CPython source:

# not a SyntaxWarning.
msg = (
f'error while attempting to bind on '
f'address {laddr!r}: '
f'{exc.strerror.lower()}'
)

The first line has obviously no expression, but the f is useful for visual
consistency, and we likely do not want a warning.

Though in the above case we can imagine the following typo :

msg = (
f'error while attempting to bind on ', #SyntaxWarning here
f'address {laddr!r}: ',
f'{exc.strerror.lower()}'
)

Easy to make and in this case, the expression-less f-string is likely an error.
In this case a syntax warning would help to distinguish that there are trailing
commas.

Another case from the cpython is the following: 

fullName = f'%s.%s.%s' % ( #SyntaxWarning here
 testCaseClass.__module__, testCaseClass.__qualname__, attrname
 )

Looking at the history; I believe the author was meaning to change to an
f-string, but got interrupted half-way and only added the prefix.

Pep 498 does not seem to say anything about f-string w/o expressions; but
test-suite appear to test that f-string without expression do not raise an
error. I do not believe that making it an error is in anyway desirable;

I believe a SyntaxWarning would align with the current warning on invalid
escape sequence, and help – mostly during refactoring, if an f-string loses 
some of its parameters, and the f"" if non-intentionally kept.

--
components: Interpreter Core
messages: 343672
nosy: mbussonn
priority: normal
severity: normal
status: open
title: Emit SyntaxWarning for f-strings without expressions ?
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com