[Python-ideas] Implicit string literal concatenation considered harmful?
Haoyi Li
haoyi.sg at gmail.com
Fri May 10 22:24:32 CEST 2013
+1; I've been bitten by this many times.
As already mentioned, one big use case where this is useful is having
multiline string literals without having all the annoying indentation leak
into your code. I think this could be easily fixed with a convenient
.dedent() or .strip_margin() function.
On Fri, May 10, 2013 at 3:54 PM, MRAB <python at mrabarnett.plus.com> wrote:
> On 10/05/2013 20:26, Alexander Belopolsky wrote:
>
>>
>>
>>
>> On Fri, May 10, 2013 at 2:48 PM, Guido van Rossum <guido at python.org
>> <mailto:guido at python.org>> wrote:
>>
>> I just spent a few minutes staring at a bug caused by a missing comma
>> -- I got a mysterious argument count error because instead of foo('a',
>> 'b') I had written foo('a' 'b').
>>
>>
>> I had a similar experience just few weeks ago. The bug was in a long
>> list written like this:
>>
>> ['item11', 'item12', ..., 'item17',
>> 'item21', 'item22', ..., 'item27'
>> ...
>> 'item91', 'item92', ..., 'item97']
>>
>> Clearly the bug crept in when more items were added. (I try to keep
>> redundant commas at the end of the list to avoid this, but not everyone
>> likes this style.)
>>
>>
>> Would it be reasonable to start deprecating this and eventually remove
>> it from the language?
>>
>>
>> +1, but I would start by requiring () around concatenated strings.
>>
>> I'm not so sure.
>
> Currently, parentheses, brackets and braces effectively make Python ignore
> a newline within them.
>
> (1
> +2)
>
> is the same as:
>
> (1+2)
>
> and:
>
> [1
> +2]
>
> is the same as:
>
> [1+2]
>
> 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.
>
>
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130510/57f9476e/attachment.html>
More information about the Python-ideas
mailing list