[Python-ideas] adding dictionaries

Nick Coghlan ncoghlan at gmail.com
Wed Jul 30 13:52:54 CEST 2014


On 30 July 2014 05:29, Andrew Barnert <abarnert at yahoo.com.dmarc.invalid> wrote:
> On Tuesday, July 29, 2014 7:36 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>
>>On Tue, Jul 29, 2014 at 07:22:34AM +0100, Paul Moore wrote:
>>> On 29 July 2014 00:04, Alexander Heger <python at 2sn.net> wrote:
>>> > D = A | B | C
>>> >
>>> > becomes
>>> >
>>> > D = dict(collections.ChainMap(C, B, A))
>>>
>>> This immediately explains the key problem with this proposal. It never
>>> even *occurred* to me that anyone would expect C to take priority over
>>> A in the operator form. But the ChainMap form makes it immediately
>>> clear to me that this is the intent.
>>
>>Hmmm. Funny you say that, because to me that is a major disadvantage of
>>the ChainMap form: you have to write the arguments in reverse order.
>
>
> I think that's pretty much exactly his point:
>
> To him, it's obvious that + should be in the order of ChainMap, and he can't even conceive of the possibility that you'd want it "backward".
>
> To you, it's obvious that + should be the other way around, and you find it annoying that ChainMap is "backward".
>
> Which seems to imply that any attempt at setting an order is going to not only seem backward, but possibly surprisingly so, to a subset of Python's users.
>
> And this is the kind of thing can lead to subtle bugs. If a and b _almost never_ have duplicate keys, but very rarely do, you won't catch the problem until you think to test for it. And if one order or the other is so obvious to you that you didn't even imagine anyone would ever implement the opposite order, you probably won't think to write the test until you have a bug in the field…

I think this is a nice way of explaining the concern.

I'll also note that, given we turned a whole pile of similarly subtle
data driven bugs into structural type errors in the Python 3
transition, I'm not exactly enamoured of the idea of adding more :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list