On Mon, Oct 21, 2019, 9:14 AM Rhodri James

> > The plus operation on two dictionaries feels far more natural as
> a vectorised merge, were it to mean anything.  E.g., I'd expect
> >
> >>>> {'a': 5, 'b': 4} + {'a': 3, 'b': 1}
> > {'a': 8, 'b': 5}
>
> That's only a natural expectation if you also expect the values in your
> dict to be addable (in the sense of doing something useful with a "+"
> operator).  It never occurs to me to make that assumption because a fair
> amount of the time it isn't true in my code.
>

I'm not arguing that we SHOULD make '+' mean recursive addition. I'm just
saying that if I never read this discussion, then later read `dict1 +
dict2` in code, that's what I'd expect.

I think a large percentage of the code I work with would operates insert
this hypothetical meaning. Values in my ducts are usually numbers, lists,
tuples, or *other dicts*. If that last had this new behavior, things would
mostly work.

I don't usually write code with:

d1 = {'purchases': [apples, bananas, pears]}
d2 = {'purchases': 17}

I could, of course. But lots of things I can do raise exceptions. Like
`dct[mutable_var] = val` (yes, technically "unhashable"). This one I
actually wind up encountering pretty often (or with sets even more).

What is proposed in this PEP is to add a meaning for dct1+dct2 that would
be well defined, but that would be DIFFERENT from the "one obvious meaning."
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/TCLT7CYN3U3PIOG5BWIFXJOEPTNOM2VU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to