Why does returning the "NotImplemented" object raise a "TypeError" only when the objects are separated by the plus sign? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why does returning the "NotImplemented" object raise a "TypeError" only when the objects are separated by the plus sign?

I had thought that the '+' sign behaves exactly like the '__add__' magic method; it seems not (the question is in the code): https://code.sololearn.com/ct7Sp8mRc0x4/?ref=app

6th Aug 2021, 8:13 PM
Calvin Thomas
Calvin Thomas - avatar
3 Answers
0
✩✮★✮✩ I had thought that returning "NotImplemented" will always raise the error. In which all cases does this raise the error, apart from __add__, __sub__, __radd__, __rsub__ and all the magic methods involving arithmetic operations and comparisons? I mean, does returning "NotImplemented" from a method raise a "TypeError" only if the method is a magic method relating to the arithmetic operations? I guess that this is a special case.
6th Aug 2021, 9:39 PM
Calvin Thomas
Calvin Thomas - avatar
0
✩✮★✮✩ But this doesn't happen when I return None, right?
6th Aug 2021, 10:25 PM
Calvin Thomas
Calvin Thomas - avatar
0
✩✮★✮✩ I see, thank you.
7th Aug 2021, 2:36 AM
Calvin Thomas
Calvin Thomas - avatar