Steve Willoughby wrote:
Lie Ryan wrote:
Jabin Jezreel wrote:
I am not allowed to do
t = (1, *(2, 3))
But I am allowed to do
def ts(*t):
....    return t
....
ts(1, *(2, 3))
(1, 2, 3)

I realize I can do
(1,) + (2,3)
(1, 2, 3)

What is the rationale behind not having t = (1, *(2, 3))
have the same semantics as the "ts" case above?

I guess because it is not clear what (1, *(2, 3)) should mean.
Parentheses when used for function call has different semantic then when
parentheses is used for tuple syntax. Parentheses in function is part of
the calling syntax, while parentheses in tuple is used only for grouping.

I'm not sure that's a strong argument against allowing "unfolding"
tuples in any expression beyond function calls, though, but it is how
Python works.

PS: anyway I just realized that since tuple is immutable, having (1,
*(2, 3)) be (1, 2, 3) would violate immutability. Maybe a list would be
a better example.

No, it doesn't.  This would be the expression for constructing a new
tuple, which would, after that point, be immutable.

What's the point? Why not just write is simply as (1, 2, 3) instead of the confusing (1, *(2, 3))? Don't say that (2, 3) might be a variable, it won't work without breaking python object model.

If such construct creates a new tuple, it would need to break python's object model, unless you make it as an special case. Python tend to avoid special case, unless it is really, really necessary.

Anyway, I think whatever good reason you have for this syntax, the BDFL will just say no.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to