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

Ben Darnell ben at bendarnell.com
Tue May 14 05:20:57 CEST 2013


On Fri, May 10, 2013 at 4:40 PM, Ezio Melotti <ezio.melotti at gmail.com>wrote:

> On Fri, May 10, 2013 at 10:54 PM, MRAB <python at mrabarnett.plus.com> wrote: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.
>

This is my experience as well.  When I've run into problems by forgetting a
comma it's nearly always been in a list, not in function arguments.  (and
it's never been between two items on the same line, so the proposal in one
of the subthreads here to disallow implicit concatenation only between two
strings on the same line wouldn't help much).

The problem is that in other languages, a trailing comma is forbidden,
while in python it is optional.  This means that lists like
  [
    1,
    2,
    3,
  ]

may or may not have a comma after the third element.  The comma is there
often enough that you can fall out of the habit of checking for it when you
extend the list.  The most pythonic solution is therefore to follow the
example of the single-element tuple and make the trailing comma mandatory ;)

-Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130513/dee0227f/attachment.html>


More information about the Python-ideas mailing list