A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-January/137933.html below:

[Python-Dev] Any grammar experts?

[Python-Dev] Any grammar experts?MRAB python at mrabarnett.plus.com
Tue Jan 27 00:24:21 CET 2015
On 2015-01-26 19:39, Petr Viktorin wrote:
> On Mon, Jan 26, 2015 at 8:29 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>> On 01/26/2015 11:24 AM, Barry Warsaw wrote:
>>> On Jan 26, 2015, at 10:55 AM, Ethan Furman wrote:
>>>
>>>> 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?
>>>
>>> In the face of ambiguity, refuse the temptation to guess.
>>
>> Lots of things are ambiguous until one learns the rules.  ;)
>
> I don't see why `f(**{'a': 12}, **{'a': 13})` should not be equivalent
> to `f(a=12, **{'a':13})` – iow, raise TypeError.
>
One the one hand we have:

 >>> foo(a=12, **{'a': 13})
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for keyword argument 'a'

and on the other hand we have:

 >>> foo(a=12, a=13)
   File "<stdin>", line 1
SyntaxError: keyword argument repeated

(Should this be a SyntaxError?)

But we also have:

 >>> {'a': 12, 'a': 13}
{'a': 13}

So, what should:

 >>> f(**from_env, **from_config)

do if there are common keys?

Raise an exception? Behave like dict.update? Behave like ChainMap?

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4