Consider a function defined as:
def fun(a, *args):
print(type(args), args)
When called, it packs the extra positional arguments as a tuple.
>>> fun(2, 3, 4)
<class 'tuple'> (3, 4)
I want to achieve a similar thing outside of function arguments. So, I thought I could achieve the same thing with extended iterable unpacking, but it always packs things as a list and never as a tuple:
# RHS is a tuple
>>> (a, *args) = (2, 3, 4)
>>> type(args)
<class 'list'>
>>> args
[3, 4] #but args is not a tuple!
Making it no different from:
# RHS is a list
>>> (a, *args) = [2, 3, 4]
>>> type(args)
<class 'list'>
>>> args
[3, 4]
I can understand that this is how it is proposed in the PEP as well.
I am asking if there is another way to achieve what I want.
Of course, I could convert args
to tuple by later doing:
>>> args = tuple(args)
>>> args
(3, 4)
If this cannot be achieved directly during the assignment.