Python data classes
Python data classes
Posted Nov 30, 2017 16:34 UTC (Thu) by mgedmin (subscriber, #34497)Parent article: Python data classes
Pedantry: NotImplemented is not an exception. It's a singleton you return from special comparison method (__eq__, __lt__ and friends) to indicate that you don't know how to compare self with the other object, which will lead to Python calling the appropriate comparison method on the other operand. For example, if you try a < b and a.__lt__(b) returns NotImplemented, Python will call b.__gt__(a). If both return NotImplemented, Python will raise a TypeError.
There is an exception with a very similar name (NotImplementedError), which sometimes leads to confusion.