The + operator looks great – I've personally experienced the papercut this solves multiple times, where it would be most natural to have "combine two dicts" operator:
return {'a': 'b'} + other_dict
but instead I had to assign to a variable and mutate with .update(), which is much more verbose:
x = {'a': 'b'}
x.update(other_dict)
return x
However, I was working in Python 2; Python 3 has
{'a': 'b', **other_dict}
and even
{**one_dict, **other_dict}
though the PEP mentions that the latter doesn't work in all circumstances. Still, it will be nice to have a more general operator; I personally don't really care whether it's called + or |.
On the other hand, the - operator seems... strange, in that it only considers the keys of its right-hand argument, and ignores the values. Seems like a footgun.
On the other hand, the - operator seems... strange, in that it only considers the keys of its right-hand argument, and ignores the values. Seems like a footgun.