[Python-ideas] Briefer string format

MRAB python at mrabarnett.plus.com
Wed Jul 22 22:21:54 CEST 2015


On 2015-07-22 19:52, Eric V. Smith wrote:
> On 07/20/2015 03:22 PM, Guido van Rossum wrote:
>> Not sure what you mean by "implicit merging" -- if you mean literal
>> concatenation (e.g. 'foo' "bar" == 'foobar') then I think it should be
>> allowed, just like we support mixing quotes and r''.
>
> Do we really want to support this? It complicates the implementation,
> and I'm not sure of the value.
>
> f'{foo}' 'bar' f'{baz}'
> becomes something like:
> format(foo) + 'bar' + format(baz)
>
> You're not merging similar things, like you are with normal string
> concatenation.
>
> And merging f-strings:
> f'{foo}' f'{bar'}
> similarly just becomes concatenating the results of some function calls.
>
> I guess it depends if you think of an f-string as a string, or an
> expression (like the function calls it will become). I don't have a real
> strong preference, but I'd like to get it ironed out logically before
> doing a trial implementation.
>
As Guido said, we can merge raw string literals.

It would be a gotcha if:

     r'{foo}' 'bar'

worked but:

     f'{foo}' 'bar'

didn't. You'd then have to how they're different even though they look
a lot alike.



More information about the Python-ideas mailing list