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

Ethan Furman ethan at stoneleaf.us
Mon Nov 3 17:22:30 CET 2014


On 11/03/2014 08:12 AM, R. David Murray wrote:
> 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).

I was wondering myself, which is why I started this thread.

--
~Ethan~


More information about the Python-Dev mailing list