I created my own Customset class which implements almost all the methods of python sets.
When I use instances of this Customset, many of the set operators fail. They fail with something similar to:
TypeError: unsupported operand type(s) for -: ‘Customset’ and Customset’
or
TypeError: ‘<=’ not supported between instances of ‘Customset’ and Customset’
The operators that fail include: -, -=, &, &=, <, <=, >, >=, ^, ^=, |, |=, ==
I expected them to map to the methods documented in:
https://docs.python.org/3.12/library/stdtypes.html#set and
https://www.w3schools.com/python/python_ref_set.asp
Yes, the <operator>
==> <method>
mappings for a custom set class do differ from the mappings for the built-in set class. There is nothing in the definition of the custom class to tell python to use the same mappings as the unique mappings for instances of set.
The actual mappings all seem to be the normal magic dundermethods for those operators:
- ==> __sub__
-= ==> __isub__
& ==> __and__
&= ==> __iand__
< ==> __lt__
<= ==> __le__
> ==> __gt__
>= ==> __ge__
^ ==> __xor__
^= ==> __ixor__
| ==> __or__
|= ==> __ior__
== ==> __eq__