Pythonification of the asterisk-based collection packing/unpacking syntax

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Dec 17 18:20:10 EST 2011


On Sat, 17 Dec 2011 12:11:04 -0800, Eelco wrote:

> > One can not state in a single line what the asterisk
> > operator does; 
...
> To cut short this line of discussion; I meant the asterisk symbol purely
> in the context of collection packing/unpacking. Of course it has other
> uses too.
> 
> Even that single use requires a whole paragraph to explain completely;
> when does it result in a tuple or a list, when is unpacking implicit and
> when not, why * versus **, and so on.

Do you think that this paragraph will become shorter if you change the 
spelling * to something else?

It takes more than one line to explain list comprehensions, content 
managers, iterators, range(), and import. Why should we care if * and ** 
also take more than one paragraph? Even if you could get it down to a 
single line, what makes you think that such extreme brevity is a good 
thing?

You might not be able to explain them in a single line, but you can 
explain them pretty succinctly:

    Varags: Inside a function parameter list, * collects an arbitrary
    number of positional arguments into a tuple. When calling functions,
    * expands any iterator into positional arguments. In both cases, **
    does the same thing for keyword arguments.

    Extended iterator unpacking: On the left hand side of an assignment,
    * collects multiple values from the right hand side into a list.


Let's see you do better with your suggested syntax. How concisely can you 
explain the three functions?

Don't forget the new type coercions (not constraints, as you keep calling 
them) you're introducing. It boggles my mind that you complain about the 
complexity of existing functionality, and your solution involves 
*increasing* the complexity with more functionality.



-- 
Steven



More information about the Python-list mailing list