Martin Panter added the comment:

This doesn’t seem like a bug to me. At least it is consistent with the rule for 
making a tuple when there are commas versus returning the direct expression 
when there are no commas:

>>> x = (1); type(x)
<class 'int'>
>>> x = (1,); type(x)
<class 'tuple'>

I don’t think it is worth changing the syntax again just to pack a single 
starred expression into a tuple without a comma. If you really want to do that, 
it would be clearer to write

expression = (1, 2)
tuple_1 = (*expression,)  # Brackets and comma suggest a tuple
tuple_2 = tuple(expression)  # Tuple constructor even more obvious

Allowing tuple packing without a comma would add a new inconsistency with 
function calls. It would conflict with your list(*(1, 2)) case:

list(*(1, 2))  # Currently equivalent to list(1, 2)
list( (*(1, 2)) )  # Would be equivalent to list( (1, 2) )

The root problem IMO is that round brackets and commas have too many 
inconsistent special cases in Python (simple expressions vs tuples, tuples with 
zero, one or more items, function calls and signatures, generator expressions, 
unpacking assignments, etc). But it may be too hard to change any of this.

----------
components: +Interpreter Core -Regular Expressions
nosy: +martin.panter
title: about starred expression -> starred tuple expression vs list display and 
function call

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30084>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to