[Python-ideas] Descouraging the implicit string concatenation

Kyle Lahnakoski klahnakoski at mozilla.com
Wed Mar 14 18:06:56 EDT 2018



On 2018-03-14 08:18, Facundo Batista wrote:
> Hello!
>
> What would you think about formally descouraging the following idiom?
>
>     long_string = (
>         "some part of the string "
>         "with more words, actually is the same "
>         "string that the compiler puts together")
>

Thank you for bring this up!  A regex through one of my programs
revealed three bugs caused by implicit concatenation in lists.  Here is
one of them:
https://github.com/klahnakoski/ActiveData-ETL/blob/etl/activedata_etl/transforms/pulse_block_to_task=_cluster.py#L897 
The missing commas were not caught until now because of the lists are
long, and deal with rare cases.

I did use implicit concatenation for a long SQL statement, and a few
long error messages, but the byte savings is not worth the increased bug
density.

>    self.db.execute(
>        "CREATE TABLE files (" +
>        "   bucket TEXT," +
>        "   key TEXT," +
>        "   name TEXT," +
>        "   last_modified REAL," +
>        "   size INTEGER," +
>        "   annotate TEXT, " +
>        "   CONSTRAINT pk PRIMARY KEY (bucket, name)" +
>        ")"
>    )

is almost identical to

>    self.db.execute(
>        "CREATE TABLE files ("
>        "   bucket TEXT,"
>        "   key TEXT,"
>        "   name TEXT,"
>        "   last_modified REAL,"
>        "   size INTEGER,"
>        "   annotate TEXT, "
>        "   CONSTRAINT pk PRIMARY KEY (bucket, name)"
>        ")"
>    )
   
It looks like I am in the market for a linter that prevents implicit
string concatenation!


More information about the Python-ideas mailing list