set and frozenset follow the number protocol, and they do not explicitly specify the inverse operations , but they get these "for free" because they implement ordinary methods (like __and__ ) .
However, inverse operations are especially useful when working with subclasses, because if the right operand is a subclass of the left operand, a reverse action is taken . But in the case of simple set and frozenset this does not matter, because they do not inherit from each other.
These inverse operations are also used if the first operand returns NotImplemented in it. But again, this is not very useful for set and frozenset , because they only allow operations with other set outputs and at least set and frozenset do not return NotImplemented when the other operand is different set .
Also, z & s does not match s.__rand__(z) , unless s is a subclass of z . Otherwise, z.__and__(s) will be attempted before s.__rand__(z) .
Therefore, I doubt that there are options for using reverse union and intersection, but it should explain "why these methods exist."
Mseifert
source share