On Mon, Feb 12, 2018 at 10:07 PM, David Mertz <mertz@gnosis.cx> wrote:
I'm not sure I'm convinced by Sylvain that Boolean needs to be an ABC in the standard library; Guido expresses skepticism.  Of course it is possible to define it in some other library that actually needs to use `isinstance(x, Boolean)` as Sylvain demonstraits in his post.  I'm not sure I'm unconvinced either, I can see a certain value to saying a given value is "fully round-trippable to bool" (as is np.bool_).

But is an ABC the way to do it? Personally, I'm skeptical that ABCs are a solution to, well, anything (as apposed to duck typing and EAFTP). Take Nick's example:

The other comparison that comes to mind would be the distinction
between "__int__" ("can be coerced to an integer, but may lose
information in the process") and "__index__" ("can be losslessly
converted to and from a builtin integer").

I suppose we could have had an Index ABC -- but that seems painful to me.

so maybe we could use a __true_bool__ special method? 

(and an operator.true_bool() function ???)

(this all makes me wish that python bools were more pure -- but way to late for that!)

I guess it comes down to whether you want to:

 - Ask the question: "is this object a boolean?"


 - Make this object a boolean

__index__ (and operator.index())  is essentially the later -- you want to make an index out of whatever object you have, if you can do so.



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception