[Python-Dev] The role of NotImplemented: What is it for and when should it be used?

R. David Murray rdmurray at bitdance.com
Mon Nov 3 17:12:13 CET 2014


On Mon, 03 Nov 2014 15:05:31 +0000, Brett Cannon <brett at python.org> wrote:
> On Mon Nov 03 2014 at 5:31:21 AM Ethan Furman <ethan at stoneleaf.us> wrote:
> 
> > Just to be clear, this is about NotImplemented, not NotImplementedError.
> >
> > tl;dr  When a binary operation fails, should an exception be raised or
> > NotImplemented returned?
> >
> 
> The docs for NotImplemented suggest it's only for rich comparison methods
> and not all binary operators:
> https://docs.python.org/3/library/constants.html#NotImplemented . But then
> had I not read that I would have said all binary operator methods should
> return NotImplemented when the types are incompatible.

Ethan opened an issue and then changed those docs, but I now believe
that the docs should be changed back (see the discussion in issue
22766).

--David


More information about the Python-Dev mailing list