Update the dictionary d with keys and values from other, which may be either a mapping or an iterable of key/value pairs. The values of other take priority when d and other share keys.
This appears to be equivalent to calling d.update(other) with no keywords:
Update the dictionary with the key/value pairs from mapping or iterable and kwargs, overwriting existing keys. Return None.
update() accepts either another object with a keys() method (in which case __getitem__() is called with every key returned from the method) or an iterable of key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: d.update(red=1, blue=2).
However, collections.abc.MutableMapping does not implement __ior__() as a mixin method despite implementing MutableMapping.update().
Was this simply an oversight in the implementation of MutableMapping, or was there a reason a definition for __ior__() was omitted? If the former, should MutableMapping implement __ior__() as follows?
Whether an oversight or not (and I would lean toward not), it’s not possible to add to the collections abcs without it being a breaking change, as these describe expectations of interfaces.
There’s a gigantic comment at the top of the file in which these are implemented which explains the rationale behind that in more detail.
Additionally, if you go back to PEP 584, it notes this issue, alongside the fact that mapping | mapping can’t be done generally since there isn’t a generic way to copy the mapping.
I have definitely made the mistake of confusing the concrete implementations of the abstracts with the abc definitions before.
It does take a second to remember that the abcs aren’t defining the contracts you get with list, tuple, set, and dict, but instead defining the minimum viable interface for something that behaves like one of those concrete classes.
Mapping makes no guarantee of key order, even though dict (now) does. It also doesn’t handle keys() the same way for example.
Any addition, abstract or not, changes what types qualify as meeting that type, and the collection abcs also serve a purpose in structural typing for python’s type system.
Not every Sequence inherits from Sequence. Part of the point of ABCs is that they can be recognized by the methods alone, without explicitly inheriting. It’s a breaking change to add methods.
Ah I stand corrected. To be more precise it’s more of the point of a protocol rather than of the point of an ABC, even though protocols are implemented as ABCs.