epiphany
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Apr 25 08:52:33 EDT 2013
On Thu, 25 Apr 2013 08:36:34 -0400, Roy Smith wrote:
> In article <5178b1db$0$29977$c3e8da3$5496439d at news.astraweb.com>,
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
>
>> The semantics of NotImplemented is that it is a signal for one object
>> to say "I don't know how to do this, let somebody else try".
>
> That's precisely the logic here. The rule says, "I don't know how to
> tell you if this is OK or not, ask another rule".
Sounds good to me then. It looks like your design is actually much closer
to what I believe the standard Python semantics are intended to be than
it appeared at first.
[...]
> Here's what the docs say about NotImplemented:
>
>> This type has a single value. There is a single object with this value.
>> This object is accessed through the built-in name NotImplemented.
>> Numeric methods and rich comparison methods may return this value if
>> they do not implement the operation for the operands provided. (The
>> interpreter will then try the reflected operation, or some other
>> fallback, depending on the operator.) Its truth value is true.
>
> It gives an example of a use by numeric methods. It doesn't say that's
> the only thing it can be used for.
Right. You can do a lot of things in Python, including shooting your foot
off :-) but that doesn't mean you should. The further away from standard
Python conventions you get, the more wary you should be. That's all.
> It also says, "Its truth value is true". Why would they document that
> fact if you weren't supposed to use it as a boolean operand?
You can use *anything* in Python in a boolean context. That's a language
feature: all objects are either truthy or falsey. As for why it is
documented for NotImplemented, I guess that's because some people might
guess that it is falsey, like None.
--
Steven
More information about the Python-list
mailing list