> no one can tell what either '+' or '|' does in this context without > guessing, because it does do neither "arithmetic addition", nor > "concatenation", nor "union set" (or bitwise op, or any other op one could > come up). '+' is more familiar or '|' might even be completely new for some > users, but this distinction does not help making '+' in this context "more > obvious". > > What I can only say for sure is that it is an operation on two dicts and > the result is possibly again a dict. So consulting the doc will be needed > in either case. > > Union set, while being commutative, is not a manifestation of the > "addition idea", but of something else - a union set idea :), which is > different from the addition idea, because it is not only more specialized, > but, and this is the important difference, requires recognition of another > concept - identity, which the addition does not need, and on the abstract > (idea) level operates differently (vaguely saying, "addition" preserves the > integrity, "union set" preserves the identity). >
> The dict merge (or update) operation is unfortunately related neither to > all "addition manifestations" nor to "union set" in a sense that it comes > from the same idea, but it is an idea on its own, because apart from the > recognition of identity (which union set requires), it also requires a > concept of association (which neither addition nor union set use or need) > and the actual operation is again different from the former two. > >> >> Using either '|' or '+' is technically not correct, if we want to have it > consistent on the abstract level. But '|' (the idea of what '|' is > representing) is more similar to what is happening in dict merge than the > addition idea. Since introducing a new (operator) symbol for that seems to > be unacceptable (for practical reasons), '|' is the best candidate we have. > Thanks for the nice run-down on operators and logic, and I mostly agree. As you say, neither is accurate due to the different mathematical structure of dictionaries as compared to sets, etc. To me '+' would seem the most natural in the sense of that is what I would have tried first, as many others have stated. From the "feeling" of it, '+' points toward 'addition', 'what comes later'. I see it as rather dangerous to use '|' union because it behaves similar - as it is not the same - confusion may be larger. Yes, you have to look up in the doc what it does - or, for the lazy, do a hand full of tests with examples (I often do that). +1 for '+'
_______________________________________________ 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/M25TZIAVJENS4PMS4BE7QCW3BK5AHQ6K/ Code of Conduct: http://python.org/psf/codeofconduct/