[Python-ideas] PEP: Dict addition and subtraction
mistersheik at gmail.com
Fri Mar 1 12:05:54 EST 2019
Looks like a good start.
I think you should replace all of the lines:
if isinstance(other, dict):
if isinstance(self, type(other)):
Since if other is an instance of a dict subclass, he should be the one to
process the addition. On the other hand, if self is an instance of the
derived type, then we are free to do the combination.
I think you should also change this wording:
"the result type will be the type of the left operand"
since the result type will be negotiated between the operands (even in your
__sub__ can be implemented more simply as a dict comprehension.
Don't forget to return self in __isub__ and __iadd__ or they won't work.
I think __isub__ would be simpler like this:
def __isub__(self, it):
if it is self:
for value in it:
I don't see why you would bother looking for keys (iter will do that
On Friday, March 1, 2019 at 11:27:54 AM UTC-5, Steven D'Aprano wrote:
> Attached is a draft PEP on adding + and - operators to dict for
> This should probably go here:
> but due to technical difficulties at my end, I'm very limited in what I
> can do on Github (at least for now). If there's anyone who would like to
> co-author and/or help with the process, that will be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas