Issue 36637: Restrict syntax for tuple literals with one element (original) (raw)

A tuple can be created with or without parentheses:

a = (1, 2, 3)

a = 1, 2, 3

While both are intuitive in this example, omitting the parentheses can lead to hard to find errors when there is only one element:

a = (1,)

a = 1,

The first is clear but the second can easily occur as a typo when the programmer actually just wanted to assign an integer (comma is next to enter on many keyboards).

I think ideally, omitting parentheses in the single element case would throw a SyntaxError.

On the other hand, I assume that it could be difficult to separate the behavior or tuple creating with an without parentheses, since the parentheses are probably not actually part of the tuple literal.