Author Devin Jeanpierre
Recipients Devin Jeanpierre, docs@python
Date 2017-04-04.22:51:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
am not sure when TypeError is the right choice. Definitely, most of the time I've seen it done, it causes trouble, and NotImplemented usually does something better.

For example, see the work in to get set to interoperate correctly with other set-like classes --- a problem caused by the use of TypeError instead of returning NotImplemented (e.g.

This advice seems to conflict with the usual and expected behavior of objects from Python: e.g. object().__lt__(1) returns NotImplemented rather than raising TypeError, despite < not "making sense" for object. Similarly for file objects and other uncomparable classes. Even complex numbers only return NotImplemented!

>>> 1j.__lt__(1j)

If this note should be kept, this section could use a decent explanation of the difference between "undefined" (should return NotImplemented) and "nonsensical" (should apparently raise TypeError). Perhaps a reference to an example from the stdlib.
Date User Action Args
2017-04-04 22:51:54Devin Jeanpierresetrecipients: + Devin Jeanpierre, docs@python
2017-04-04 22:51:53Devin Jeanpierresetmessageid: <>
2017-04-04 22:51:53Devin Jeanpierrelinkissue29986 messages
2017-04-04 22:51:53Devin Jeanpierrecreate