
On Fri, Jul 24, 2015 at 10:27 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
Greg Ewing <greg.ewing@canterbury.ac.nz> writes:
Steven D'Aprano wrote:
I don't think I want this behaviour:
f'{spam}' '{eggs}' => format(spam) + '{eggs}'
What do you think should happen in this case:
'{spam}' f'{eggs}'
It would seem very strange to me if the f infected strings *before* it as well as after it.
The existing behaviour of implicit concatenation doesn't give much of a guide here, unfortunately::
>>> 'foo\abar' r'lorem\tipsum' 'wibble\bwobble' 'foo\x07barlorem\\tipsumwibble\x08wobble'
>>> type(b'abc' 'def' b'ghi') File "<stdin>", line 1 SyntaxError: cannot mix bytes and nonbytes literals
So, the ‘b’ prefix expects to apply to all the implicitly-concatenated parts (and fails if they're not all bytes strings); the ‘r’ prefix expects to apply only to the one fragment, leaving others alone.
Is the proposed ‘f’ prefix, on a fragment in implicit concatenation, meant to have behaviour analogous to the ‘r’ prefix or the ‘b’ prefix, or something else? What's the argument in favour of that choice?
It *must* work like r'' does. Implicit concatenation must be thought of as letting each string do its thing and then concatenating using '+', just optimized if possible. The error for b'' comes out because the '+' refuses b'' + ''. I find it a sign of the times that even this simple argument goes on and on forever. Please stop the thread until Eric has had the time to write up a PEP. -- --Guido van Rossum (python.org/~guido)