[Python-ideas] Implicit string literal concatenation considered harmful?

Andrew Barnert abarnert at yahoo.com
Sat May 11 07:12:58 CEST 2013


On May 10, 2013, at 20:37, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On Sat, May 11, 2013 at 10:29 AM, Bruce Leban <bruce at leapyear.org> wrote:
>> I got bit by this quite recently, leaving out a comma in a long list of
>> strings and I only found the bug by accident.
>> 
>> This being python "ideas" I'll throw one out.
>> 
>> Add another prefix character to strings:
>> 
>>    a = [m'abc'
>>         'def']   # equivalent to ['abcdef']
> 
> As MRAB suggested, a prefix for a compile time dedent would likely be
> more useful - then you'd just use a triple quoted string and be done
> with it. The other one I occasionally wish for is a compile time
> equivalent of str.split (if we had that, we likely wouldn't see APIs
> like collections.namedtuple and enum.Enum accepting space separated
> strings).

Why does it need to be compile time? Do people really run into cases that frequently where the cost of concatenating or dedenting strings at import time is significant?

If so, it seems like something more dramatic might be warranted, like allowing the compiler to assume that method calls on literals have the same effect at compile time as at runtime so it can turn them into constants. (Doesn't the + optimization already make that assumption anyway?)


More information about the Python-ideas mailing list