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

Joshua Landau joshua.landau.ws at gmail.com
Mon Jul 8 05:02:40 CEST 2013


On 8 July 2013 03:58, Joshua Landau <joshua.landau.ws at gmail.com> wrote:
> On 8 July 2013 01:56, Jan Kaliszewski <zuo at chopin.edu.pl> wrote:
>> 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).
>
> My first opinion would be that if relaxation is something people find
> useful, it would be suited to a separate proposal; it seems outside of
> this PEP's scope á mon avis.

Also, surely if the PEP goes through it would be easy enough to write:

func(**{**kwargs, **overlapping_kwargs})

which is a more explicit, less special case method. It's
less-efficient, but it should handle the simple cases.

I'm not sure if it makes intuitive sense though.


More information about the Python-ideas mailing list