[Python-Dev] Decimal & returning NotImplemented (or not)

Nick Craig-Wood nick at craig-wood.com
Wed Mar 2 10:55:15 CET 2005

On Tue, Mar 01, 2005 at 05:55:50PM -0500, Neil Schemenauer wrote:
> On Tue, Mar 01, 2005 at 11:45:43PM +1000, Nick Coghlan wrote:
> > Interesting. In that case, my other suggestion was to have raising 
> > NotImplementedError from a special method be the equivalent of returning 
> > NotImplemented (which makes life much easier for a class like Decimal which 
> > has an internal method for doing the type conversion).
> NotImplementedError has nothing to do with the NotImplemented
> singleton.  It's unfortunate about the naming.  IMO, Decimal should
> be returning NotImplemented instead of raising TypeError.

That seems very un-pythonic to me - return an error?

If you look at the patched Decimal module you'll see all sorts of
contortions necessary to accomodate it, wheras if it could just raise
NotImplementedError or NotImplementedTypeError it would make the code
a lot cleaner.

I have to say when I read the python language docs, I assumed there
was a mistake in them and they meant to say "raise
NotImplementedError" instead of "return NotImplemented".

Why is it like that?  And could it be changed (Nick Coghlan's proposal
seems good to me)?

Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick

More information about the Python-Dev mailing list