epiphany

Ethan Furman ethan at stoneleaf.us
Wed Apr 24 22:25:37 EDT 2013


On 04/24/2013 06:35 PM, Steven D'Aprano wrote:
> Objects are supposed to return NotImplemented from special dunder methods
> like __add__, __lt__, etc. to say "I don't know how to implement this
> method for the given argument". Python will then try calling the other
> object's special method. If both objects return NotImplemented, Python
> falls back on whatever default behaviour is appropriate.
>
> So, knowing nothing of your application, I fear that this is an abuse of
> NotImplemented's semantics. If a rule returns NotImplemented, I would
> expect your application to fall back on a different rule. If that's not
> the case, you're using it in a non-standard way that will cause confusion
> for those with expectations of what NotImplemented means.

Why would you assume some random application is going to deal with NotImplemented the same way the python interpreter 
does?  And even the interpreter isn't consistent -- sometimes it will return false (__eq__) and sometimes it will raise 
an Exception (__add__).

I hardly think it an abuse of NotImplemented to signal something is not implemented when NotImplemented means, um, not 
implemented.

possibly-not-implemented-ly yours,

--
~Ethan~



More information about the Python-list mailing list