[Python-Dev] 1-tuple trailing comma
Guido van Rossum
guido at python.org
Tue Dec 18 19:41:43 CET 2007
On Dec 18, 2007 7:31 AM, Calvin Spealman <ironfroggy at socialserve.com> wrote:
> I just had an issue brought up by another developer who had a
> trailing comma on an assignment causing a 1-tuple he did not expect.
> We were talking about it and came to the conclusion that it is at
> least worth bringing up the idea of enforcing a SyntaxError in the
> case of this. 1-tuple syntax is already an odd-man-out, so requiring
> more explicitness about it would catch some errors and be more
> readable. I think we could agree that a tuple of 2 or more elements
> is much easier to read without parens than a 1-tuple without parens.
> Aside from assignment I can't think of a single place when one would
> construct a 1-tuple without parens.
>
> This is the offending erroneous and hard-to-catch code:
>
> if foo:
> bar = 3,
> L = [1,
> 2,
> bar]
>
> Would there be any possibility in considering further refining the 1-
> tuple syntax to require parens because of its nature?
Why don't you try to come up with a patch to see how feasible this is?
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list