[Python-ideas] PEP for issue2292, "Missing *-unpacking generalizations"

Jan Kaliszewski zuo at chopin.edu.pl
Mon Jul 8 02:56:01 CEST 2013


On 07.07.2013 01:03, Joshua Landau wrote:

>     Function calls may accept an unbound number of ``*`` and ``**``
> unpackings. Arguments can now occur in any position in a function
> call. As usual, keyword arguments always go to their respective keys
> and positional arguments are then placed into the remaining 
> positional
> slots. In approximate pseudo-notation::
>
>         function(
>             argument or keyword_argument or *args or **kwargs,
>             argument or keyword_argument or *args or **kwargs,
>             ...

What do you exactly mean by "remaining positional slots"? Please note
that the current behaviour is to raise TypeError when several (more
than 1) arguments match the same parameter slot. IMHO it must be kept.

Another question is related to this matter as well: if we adopt
the idea of more than one **kwargs in function call -- what about
key duplication? I.e. whether:

     fun(**{'a': 1}, **{'a': 2})

...should raise TypeError as well, or should it be equivalent to
fun(a=2)?

My first thought was that it should raise TypeError -- prohibition
of parameter duplication is a simple and well settled rule for Python
function calls.  On second thought: it could be relaxed a bit if we
agreed about another rule that would be simple enough, e.g.: "for
anything *after* the first '**kwargs' (or maybe also bare '**,'?)
another rule is applied: later arguments override earlier (looking
from left to right), as in dict(...)/.update(...) or as in
{**foo, **bar} in literals (if the rest of the PEP is accepted).

Cheers.
*j



More information about the Python-ideas mailing list