[Python-ideas] PEP: Dict addition and subtraction

Brandt Bucher brandtbucher at gmail.com
Tue Mar 5 01:48:07 EST 2019

I agree with David here. Subtraction wasn’t even part of the original discussion — it seems that it was only added as an afterthought because Guido felt they were natural to propose together and formed a nice symmetry.

It’s odd that RHS values are not used at all, period. Further, there’s no precedent for bulk sequence/mapping removals like this... except for sets, for which it is certainly justified.

I’ve had the opportunity to play around with my reference implementation over the last few days, and despite my initial doubts, I have *absolutely* fallen in love with dictionary addition — I even accidentally tried to += two dictionaries at work on Friday (a good, but frustrating, sign). For context, I was updating a module-level mapping with an imported one, a use case I hadn’t even previously considered.

I have tried to fall in love with dict subtraction the same way, but every code sketch/test I come up with feels contrived and hack-y. I’m indifferent towards it, at best.

TL;DR: I’ve lived with both for a week. Addition is now habit, subtraction is still weird.

> Nice branch name! :)

I couldn’t help myself.


More information about the Python-ideas mailing list