[Python-Dev] 1-tuple trailing comma

Calvin Spealman ironfroggy at socialserve.com
Tue Dec 18 16:31:31 CET 2007


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?


More information about the Python-Dev mailing list