Title: tuple - single value with comma is assigned as type tuple
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Jelle Zijlstra, acue, steven.daprano
Priority: normal Keywords:

Created on 2016-06-05 17:06 by acue, last changed 2016-06-05 17:14 by steven.daprano. This issue is now closed.

Messages (3)
msg267434 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2016-06-05 17:06
A single value terminated by a comma is assigned to be a tuple, even when missing parenthesis.

a=(1)  =>  a=1    OK/defined as
a=(1,) =>  a=(1,) OK
a=1,   =>  a=(1,) ???

Is the latter intended?

In [4]: a=1,

In [5]: print a

In [6]: type(a)
Out[6]: tuple
msg267436 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2016-06-05 17:09
Yes, this is intentional. It is documented in 

"The trailing comma is required only to create a single tuple"
msg267438 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-06-05 17:14
Yes, it is intended. Commas create tuples, not parentheses. (With the exception of the empty tuple.) The parens are just for grouping and precedence. `1,` is a tuple, regardless of whether you use parens around it or not.
Date User Action Args
2016-06-05 17:14:57steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg267438

resolution: not a bug
stage: resolved
2016-06-05 17:09:08Jelle Zijlstrasetnosy: + Jelle Zijlstra
messages: + msg267436
2016-06-05 17:06:46acuecreate