Why do operators and methods of built-in types differ

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jan 31 16:16:03 CET 2009

En Sat, 31 Jan 2009 11:03:13 -0200, andrew cooke <andrew at acooke.org>  

>> Just a correction: according to the doc, NotImplemented is not an
>> error, but a returned value.
> curious, so it is.  i wonder why there is both a special return value
> (NotIMplemented) and a related exception (NotImplementedError).  seems
> very odd to have a value...

I consider it an optimization. Raising an exception is more costly than  
returning a value, and this failure is likely to happen often (not all  
types define all possible operators). AFAIK this is only recognized by the  
binary operators (__add__, __iadd__, etc) and rich comparisons (__eq__,  
__lt__, etc.)

Gabriel Genellina

More information about the Python-list mailing list