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

Ezio Melotti ezio.melotti at gmail.com
Fri May 10 22:40:08 CEST 2013


On Fri, May 10, 2013 at 10:54 PM, MRAB <python at mrabarnett.plus.com> wrote:
> Under the proposal:
>
> ("a"
> "b")
>
> or:
>
> ("a" "b")
>
> would be the same as:
>
> ("ab")
>
> but:
>
> ["a"
> "b"]
>
> or:
>
> ["a" "b"]
>
> would be a syntax error.
>

This would actually be fine with me.  I use implicit string literal
concatenation mostly within (...), and even though I've seen (and
sometimes written) code like
['this is a '
 'long string',
 'this is another '
 'long string']
I agree that requiring extra (...) in this case is reasonable, i.e.:
[('this is a '
  'long string'),
 ('this is another '
  'long string')]
The same would apply to other literals like {...} (for both sets and
dicts), and possibly for tuples too (assuming that it's possible to
figure out when a tuple is being created).

I also write code like:
raise SomeException('this is a long message '
                    'that spans 2 lines')
or even:
self.assertTrue(somefunc(), 'somefunc() returned '
                'a false value and this is wrong')
In these cases I wouldn't like redundant (...) (or even worse extra
'+'s), especially for the first case.

I also think that forgetting a comma in a list of function args
between two string literal args is quite uncommon, whereas forgetting
it in a sequence of strings (list, set, dict, tuple) is much more
common, so this approach should cover most of the cases.

Best Regards,
Ezio Melotti



More information about the Python-ideas mailing list