[issue30084] starred tuple expression vs list display and function call

2017-04-16 Thread umedoblock

umedoblock added the comment:

Sorry and thanks to Martin and Steven.
I agree with your post about first my post.
I understand "(*x) is equivalent to just bare *x."

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com




[issue30084] starred tuple expression vs list display and function call

2017-04-16 Thread Steven D'Aprano

Steven D'Aprano added the comment:

> list expression pass starred expression, the other hand
> tuple expression cannot pass starred expression.

You are misinterpreting what you are seeing.

( ) is not a tuple expression (except for the special case of empty brackets, 
which makes an empty tuple). It's just grouping an expression. So (*x) is 
equivalent to just bare *x.

To make a tuple, you need a comma.

Apart from the empty tuple, the brackets are just for grouping. Put a comma 
after the starred expression and it will work:

py> t = 1, 2
py> t
(1, 2)
py> (*t,)
(1, 2)


The trailing comma is allowed in lists as well:

py> [*t,]
[1, 2]


I agree with Martin: there's no bug here, the behaviour is consistent with the 
way tuples and lists are normally created, and there's no need to make (*t) yet 
another special case.

If you really want to argue in favour of this change, I suggest you discuss it 
on the Python-Ideas mailing list and see if you can get community consensus for 
it. *If* you get agreement that this is a good idea, then you can re-open this.

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30084] starred tuple expression vs list display and function call

2017-04-16 Thread Martin Panter

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)

>>> x = (1,); type(x)


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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com