NotImplemented is not supposed to be used in any operation. It's just a special value used in coercion since raising exceptions would be too costly.
In your example you would need to check for this special value using the "is" comparison. See https://www.python.org/dev/peps/pep-0208/ and https://www.python.org/dev/peps/pep-0207/ for details. On 3/11/2020 10:42 AM, Steve Jorgensen wrote: > I realize this is probably something that would be hard to change for > compatibility reasons. Maybe someone can think of a way around that though? > > It seems to me that `not NotImplemented` should result in `NotImplemented` > and attempting to convert it to `bool` should raise a `TypeError` exception. > > 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> > ``` > > Currently, this will not work because `NotImplemented` is truthy and `not > NotImplemented` is `False`, so it is necessary to complicate the > implementations of `__lt__` and `__le__` to specifically check whether the > value returned from the complementary method returned `NotImplemented` or not. > > If the value of `not NotImplemented` was `NotImplemented` then the coding > pattern above would simply work. > _______________________________________________ > Python-ideas mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/U7GOYMMMBQQPSD45JDNCSOO7VULDZTD6/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Mar 11 2020) >>> Python Projects, Coaching and Support ... https://www.egenix.com/ >>> Python Product Development ... https://consulting.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/NOV3DLUHLWT3QF3TNQNIOLIEUCWN3MDW/ Code of Conduct: http://python.org/psf/codeofconduct/
