|| ||Bruce Leban <bruce-xiBsuWBksRxg9hUCZPvPmw-AT-public.gmane.org> |
|| ||Nick Coghlan <ncoghlan-Re5JQEeQqe8AvxtiuMwx3w-AT-public.gmane.org> |
|| ||Re: Implicit string literal concatenation considered
|| ||Fri, 10 May 2013 17:29:28 -0700|
|| ||Python-Ideas <python-ideas-+ZN9ApsXKcEdnm+yROfE0A-AT-public.gmane.org>|
|| ||Article, Thread
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']
A string with an m prefix is continued on one or more following lines. A
string must have an m prefix to be continued (but this change would have to
be phased in). A conversion tool need merely recognize the string
continuations and insert m's. I chose the m character for multi-line but
the character choice is available for bikeshedding. The m prefix can be
combined with u and/or r but not with triple-quotes. The following are not
b = ['abc' # syntax error (m is required for continuation)
c = [m'abc'] # syntax error (when m is used, continuation lines must
d = [m'abc'
m'def'] # syntax error (m only allowed for first string)
The reason to prohibit cases c and d guard against comma errors with these
forms. Consider these cases with missing or extra commas.
e = [m'abc', # extra comma causes syntax error
f = [m'abc' # missing comma causes syntax error
Yes, I know this doesn't guard against all comma errors. You could protect
against more with prefix and suffix (e.g., an m at the end of the last
string) but I'm skeptical it's worth it.
Conversion to this could be done in three stages:
(1) accept m's (case a), deprecate missing m's (case b), error for misused
m's (case c-f)
(2) warn on missing m's (case b)
(3) error on missing m's (case b)
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
Python-ideas mailing list
to post comments)