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').
This is a fairly common mistake, and IIRC at Google we even had a lint
rule against this (there was also a Python dialect used for some
specific purpose where this was explicitly forbidden).
Now, with modern compiler technology, we can (and in fact do) evaluate
compile-time string literal concatenation with the '+' operator, so
there's really no reason to support 'a' 'b' any more. (The reason was
always rather flimsy; I copied it from C but the reason why it's
needed there doesn't really apply to Python, as it is mostly useful
inside macros.)
Would it be reasonable to start deprecating this and eventually remove
it from the language?
--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python...@python.org
http://mail.python.org/mailman/listinfo/python-ideas
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').
Would it be reasonable to start deprecating this and eventually remove
it from the language?
On Fri, 10 May 2013 11:48:51 -0700I'm rather -1. It's quite convenient and I don't want to add some '+'
Guido van Rossum <gu...@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').
>
> This is a fairly common mistake, and IIRC at Google we even had a lint
> rule against this (there was also a Python dialect used for some
> specific purpose where this was explicitly forbidden).
>
> Now, with modern compiler technology, we can (and in fact do) evaluate
> compile-time string literal concatenation with the '+' operator, so
> there's really no reason to support 'a' 'b' any more. (The reason was
> always rather flimsy; I copied it from C but the reason why it's
> needed there doesn't really apply to Python, as it is mostly useful
> inside macros.)
>
> Would it be reasonable to start deprecating this and eventually remove
> it from the language?
signs everywhere I use it. I'm sure many people also have long string
literals out there and will have to endure the pain of a dull task to
"fix" their code.
However, in your case, foo('a' 'b') could raise a SyntaxWarning, since
the "continuation" is on the same line.
Regards
Antoine.
_______________________________________________
Python-ideas mailing list
Python...@python.org
http://mail.python.org/mailman/listinfo/python-ideas
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
Tuples.
There are plenty of examples where the continuation isn't on the same
line (some were already posted here).
def fun(a, b, c,):
>>> x = 1,>>> x
(1,)
>>> x == 1, # inconsistency?
(False,)
>>> x == (1,)
True
I'd prefer that the syntax for creating one-tuples requires the parenthesis, and that trailing commas are disallowed.>>> y = a_very_long_call(param1, param2, param3), # this trailing comma is difficult to spot
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').
This is a fairly common mistake, and IIRC at Google we even had a lint
rule against this (there was also a Python dialect used for some
specific purpose where this was explicitly forbidden).
Now, with modern compiler technology, we can (and in fact do) evaluate
compile-time string literal concatenation with the '+' operator, so
there's really no reason to support 'a' 'b' any more. (The reason was
always rather flimsy; I copied it from C but the reason why it's
needed there doesn't really apply to Python, as it is mostly useful
inside macros.)
Would it be reasonable to start deprecating this and eventually remove
it from the language?
On 11 May 2013 04:50, "Guido van Rossum" <gu...@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').
>
> This is a fairly common mistake, and IIRC at Google we even had a lint
> rule against this (there was also a Python dialect used for some
> specific purpose where this was explicitly forbidden).
>
> Now, with modern compiler technology, we can (and in fact do) evaluate
> compile-time string literal concatenation with the '+' operator, so
> there's really no reason to support 'a' 'b' any more. (The reason was
> always rather flimsy; I copied it from C but the reason why it's
> needed there doesn't really apply to Python, as it is mostly useful
> inside macros.)
>
> Would it be reasonable to start deprecating this and eventually remove
> it from the language?
I could live with it if we get "dedent()" as a string method. I'd be even happier if constant folding was extended to platform independent method calls on literals, but I don't believe there's a sane way to maintain the "platform independent" constraint.
OTOH, it's almost on the scale of "remove string mod formatting". Shipping at least a basic linting tool in the stdlib would probably be almost as effective and substantially less disruptive. lib2to3 should provide some decent infrastructure for that.
Cheers,
Nick.
On May 10, 2013 7:51 PM, "Nick Coghlan" <ncog...@gmail.com> wrote:
>
>
> On 11 May 2013 04:50, "Guido van Rossum" <gu...@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').
> >
> > This is a fairly common mistake, and IIRC at Google we even had a lint
> > rule against this (there was also a Python dialect used for some
> > specific purpose where this was explicitly forbidden).
> >
> > Now, with modern compiler technology, we can (and in fact do) evaluate
> > compile-time string literal concatenation with the '+' operator, so
> > there's really no reason to support 'a' 'b' any more. (The reason was
> > always rather flimsy; I copied it from C but the reason why it's
> > needed there doesn't really apply to Python, as it is mostly useful
> > inside macros.)
> >
> > Would it be reasonable to start deprecating this and eventually remove
> > it from the language?
>
> I could live with it if we get "dedent()" as a string method. I'd be even happier if constant folding was extended to platform independent method calls on literals, but I don't believe there's a sane way to maintain the "platform independent" constraint.
>
> OTOH, it's almost on the scale of "remove string mod formatting". Shipping at least a basic linting tool in the stdlib would probably be almost as effective and substantially less disruptive. lib2to3 should provide some decent infrastructure for that.
I have cc'd the code-quality mailing list since several linger authors are subscribed there.
I think you could live with
x = ('foo\n' +
'bar\n' +
'baz\n'
)
as well... (Extra points if you figure out how to have a + on the last line too. :-)
(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)
Does this earn a point?
x = (+ 'foo\n'
+ 'bar\n'
+ 'baz\n'
)
Would it be reasonable to start deprecating this and eventually remove
it from the language?
x = 0
if x:
x = 9**9**9
Maybe "/"? ;)
Would it be reasonable to start deprecating this and eventually remove
it from the language?
Your first example is a regex, which could be used as-is.
Your second example is indented five levels deep. That is a coding
style which I would propose to write differently for better readability.
And if you stick with it, why not use the "+"?
I want to support constant strings, which should not be somewhere
in the middle of code. Your second example is computed, anyway,
not the case that I want to solve.
cheers - chris
--
Christian Tismer :^) <mailto:tis...@stackless.com>
Software Consulting : Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/
14482 Potsdam : PGP key -> http://pgp.uni-mainz.de
phone +49 173 24 18 776 fax +49 (30) 700143-0023
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
_______________________________________________
You're not addressing the main point I was trying to make :-)
Triple-quoted strings work for strings that are supposed to
have embedded newlines, but they don't provide a good alternative
for long strings without embedded newlines.
Regarding using '+' in these cases: of course that would be
possible, but it clutters up the code, often requires additional
parens, it's slower and can lead to other weird errors when
forgetting parens, which are not much different than the one
Guido mentioned in his original email.
In all the years I've been writing Python, I've only very rarely
had an issue with missing commas between strings. Most cases I
ran into were missing commas in lists of tuples, not strings:
l = [
'detect_target_type',
(None, Is, '"', +1, 'double_quoted_target')
(None, Is, '\'', +1, 'single_quoted_target'),
(None, IsIn, separators, 'unquoted_target', 'empty_target'),
]
This gives:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
TypeError: 'tuple' object is not callable
:-)
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 11 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2013-05-07: Released mxODBC Zope DA 2.1.2 ... http://egenix.com/go46
2013-05-06: Released mxODBC 3.2.3 ... http://egenix.com/go45
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
On Fri, May 10, 2013 at 10:54 PM, MRAB <pyt...@mrabarnett.plus.com> wrote:I also think that forgetting a comma in a list of function argsbetween 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.
On 11.05.2013 19:05, Christian Tismer wrote:
> I think a simple stripping of white-space in
>
> text = s"""
> leftmost column
> two-char indent
> """
>
> would solve 95 % of common indentation and concatenation cases.
> <snipped>
This is not a good solution for long lines where you don't want to
have embedded line endings. Taken from existing code:
_litmonth = ('(?P<litmonth>'
'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|'
'mär|mae|mrz|mai|okt|dez|'
'fev|avr|juin|juil|aou|aoû|déc|'
'ene|abr|ago|dic|'
'out'
')[a-z,\.;]*')
or
raise errors.DataError(
'Inconsistent revenue item currency: '
'transaction=%r; transaction_position=%r' %
(transaction, transaction_position))
It's taken out of context, just to demonstrate some real world
example of how long strings are broken down to handy 80 char
code lines.
The _litmonth variable is used as component to build other REs
and those typically also contain (important) whitespace,
so re.VERBOSE won't work.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, May 14 2013)
It's taken out of context, just to demonstrate some real world> The _litmonth example looks like a candidate for re.VERBOSE and a
> triple-quoted string, though.
example of how long strings are broken down to handy 80 char
code lines.
The _litmonth variable is used as component to build other REs
and those typically also contain (important) whitespace,
so re.VERBOSE won't work.
>> raise errors.DataError(
>> 'Inconsistent revenue item currency: '
>> 'transaction=%r; transaction_position=%r' %
>> (transaction, transaction_position))
>
> Agreed. I use the implicit concatenation a lot for exception
> messages like the one above
Me too.
But what do you think about:
raise errors.DataError(
'Inconsistent revenue item currency: '
c'transaction=%r; transaction_position=%r' %
(transaction, transaction_position))
c'...' -- for explicit string (c)ontinuation or (c)oncatenation.
Regards.
*j
For the record, I know this isn't the point of your message, but you're
probably missing 'fév' (accented) above :-)
Regards
Antoine.
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').
This is a fairly common mistake, and IIRC at Google we even had a lint
rule against this (there was also a Python dialect used for some
specific purpose where this was explicitly forbidden).
Now, with modern compiler technology, we can (and in fact do) evaluate
compile-time string literal concatenation with the '+' operator, so
there's really no reason to support 'a' 'b' any more. (The reason was
always rather flimsy; I copied it from C but the reason why it's
needed there doesn't really apply to Python, as it is mostly useful
inside macros.)
Would it be reasonable to start deprecating this and eventually remove
it from the language?
--
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python...@python.org
http://mail.python.org/mailman/listinfo/python-ideas
I'm -1 on it myself.
I'd expect c'' to act like b'' or u'' or r'': making a "string"-ish
thing in a special way. But c'' doesn't; the nearest analog is r''
but c'' goes _backwards_.
I much prefer:
+ 'foo'
over
c'foo'
The former already works and is perfectly clear about what it's
doing. The "c" does not do it any better and is easier to miss,
visually.
Cheers,
--
Cameron Simpson <c...@zip.com.au>
On the contrary of what you may think, your hacker is fully aware
of your company's dress code. He is fully aware of the fact that it
doesn't help him to do his job.
- Gregory Hosler <gregory...@eno.ericsson.se>