[Python-Dev] Any grammar experts?
Ethan Furman
ethan at stoneleaf.us
Mon Jan 26 20:04:25 CET 2015
On 01/26/2015 10:55 AM, Ethan Furman wrote:
> On 01/26/2015 10:40 AM, Paul Moore wrote:
>
>> There *are* some nastily non-intuitive corner cases (for example, if
>> from_env={'a':12} and from_config={'a':13}, I don't have any sort of
>> intuition as to what a would be in f(**from_env, **from_config). I'd
>> go with 12 because the PEP links multiple **-unpackings with
>> collections.ChainMap, but I wouldn't dare rely on that guess).
>
> In the your example
>
> from_env = {'a': 12}
> from_config = {'a': 13}
>
> f(**from_env, **from_config)
>
> I would think 'a' should be 13, as from_config is processed /after/ from_env.
>
> So which is it?
Going to the PEP:
kwargs = dict(kw_arguments)
kwargs.update(more_arguments)
function(**kwargs)
or, if you know to do so:
from collections import ChainMap
function(**ChainMap(more_arguments, arguments))
I see the arguments to ChainMap are reversed (more_arguments is first), so in Paul's example 'a' would be 13.
--
~Ethan~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150126/01a6b1a5/attachment.sig>
More information about the Python-Dev
mailing list