[Python-Dev] ',' precedence in documentation]

Nick Coghlan ncoghlan at gmail.com
Tue Sep 16 11:33:35 CEST 2008


Greg Ewing wrote:
> Steven D'Aprano wrote:
> 
>> I was confused about the role of commas, and totally gobsmacked when I
>> discovered that commas make tuples everywhere except when following an
>> except statement.
> 
> Um... you've never written a function call with more than
> one argument before? :-)
> 
The existence of *args syntax makes that one a little blurry - there's
often a hidden tuple of arguments involved, and it is still a case of
"multiple expressions separated by commas". The special handling for
varargs and varkwds expansion and keyword arguments are marked within
the expressions with their own special syntax. Similarly, even though
there is no actual tuple created in list, dict and set displays,
function parameter lists and unpacking to multiple targets in an
assignment statement, the usages share the characteristic that the
things being separated are by and large equivalent.

So to answer my own question from earlier in the thread, except clauses
and assert statements are special because they are the only places where
the expressions to the left and right of the comma relate to completely
different concepts. We're fixing except clauses by replacing that comma
with an 'as', but assert statements are still a bit odd.

And to suggest another colour for the bikeshed, what if we just made
"assert" a normal builtin, and required people to compile them out
explicitly in optimised code via:

  if __debug__: assert(whatever, msg="whatever broke!")

A source code transform (ala 2to3) could easily translate the old assert
statements to the above.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
            http://www.boredomandlaziness.org


More information about the Python-Dev mailing list