On Mar 11, 2020, at 02:42, Steve Jorgensen <ste...@stevej.name> wrote: > > Take the following example: > > ``` > def __lt__(self, other): > return not self.__ge__(other): > > def __le__(self, other): > return not self.__gt__(other): > > def __ge__(self, other): > <some code that might or might not return NotImplemented> > ```
Usually you can just use @total_ordering. Or, if you’re doing something almost but not quite like total_ordering and you need to do it for 20 types, you write your own variation on total_ordering (or a base class or metaclass instead of a decorator, if appropriate). When you can’t, often you just want `return not self >= other`, much like a delegating __iter__ usually wants `yield from iter(other)` rather than `yield from other.__iter__()`. When you really do need to call the dunder methods directly for a good reason, you really do need to deal with their API, including testing for NotImplemented with is. The hard part of the design is thinking through the reverse-direction cases that NotImplemented implies (both with subclasses and with unrelated classes), not knowing how to write the extra line or two of implementation. So this doesn’t seem like much of a problem, much less a problem worth breaking fundamental truthiness for a builtin type. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DAMJDCJWYF5DMFC5JUIVJJJTXDAEP4QM/ Code of Conduct: http://python.org/psf/codeofconduct/