On 8 July 2013 03:58, Joshua Landau <joshua.landau.ws@gmail.com> wrote:
On 8 July 2013 01:56, Jan Kaliszewski <zuo@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.