[Python-3000] requiring parens around singleton tuples

Neal Norwitz nnorwitz at gmail.com
Mon Dec 4 06:45:21 CET 2006


In looking at this and some other stuff, I thought about this code:

 x = 1,

How about requiring parens around (1,)?  It kinda sucks to make it
inconsistent by only requiring parens for singleton tuples.  But it
might prevent more errors and make it much harder to miss the comma.
I got this idea while reading about requiring parens in list comps
(from 3100):

   This will make list comprehensions more similar to generator comprehensions.
   [x for x in 1, 2] will need to be:  [x for x in (1, 2)]

This would apply to x, = 1 as well (ie, both LHS and RHS).  Parens are
already required for the empty tuple, this would extend it slightly.
I'm not suggestion parens be required for creating/unpacking tuples
that have 2 or more elements.

n


More information about the Python-3000 mailing list