[Python-ideas] Descouraging the implicit string concatenation

Facundo Batista facundobatista at gmail.com
Wed Mar 14 08:18:30 EDT 2018


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")

We should write the following, instead:

    long_string = (
        "some part of the string " +
        "with more words, actually is the same " +
        "string that the compiler puts together")

I know that "no change to Python itself" is needed, but having a
formal discouragement of the idiom will help in avoiding people to
fall in mistakes like:

fruits = {
    "apple",
    "orange"
    "banana",
    "melon",
}

(and even making the static analysers, like pyflakes or pylint, to
show that as a warning)

Note that there's no penalty in adding the '+' between the strings,
those are resolved at compilation time.

Thanks!!

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
Twitter: @facundobatista


More information about the Python-ideas mailing list