[Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-12 Thread Sylvain MARIE
The numbers module provides very useful ABC for the 'numeric tower', able to abstract away the differences between python primitives and for example numpy primitives. I could not find any equivalent for Booleans. However numpy defines np.bool too, so being able to have an abstract Boolean class

Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-12 Thread Steven D'Aprano
On Mon, Feb 12, 2018 at 09:41:04AM +, Sylvain MARIE wrote: > The numbers module provides very useful ABC for the 'numeric tower', > able to abstract away the differences between python primitives and > for example numpy primitives. > I could not find any equivalent for Booleans. > However nu

Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-12 Thread Guido van Rossum
TBH I've found the numeric tower a questionable addition to Python's stdlib. For PEP 484 we decided not to use it (using the concrete types, int, float etc. instead). So I'm not excited about adding more like this, especially since essentially *everything* can be used in a Boolean context. If your

Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-12 Thread David Mertz
NumPy np.bool_ is specifically not a subclass of any np.int_. If it we're, there would be an ambiguity between indexing with a Boolean array and an array of ints. Both are meaningful, but they mean different things (mask vs collection of indices). Do we have other examples a Python ABC that exist

Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-12 Thread Nick Coghlan
On 13 February 2018 at 02:14, David Mertz wrote: > NumPy np.bool_ is specifically not a subclass of any np.int_. If it we're, > there would be an ambiguity between indexing with a Boolean array and an > array of ints. Both are meaningful, but they mean different things (mask vs > collection of in

Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

2018-02-12 Thread David Mertz
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 unconvin