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

Sylvain MARIE sylvain.marie at schneider-electric.com
Mon Feb 19 08:58:06 EST 2018


> A thought just occurred to me. Maybe we should just add a Boolean class to numbers?

That would be great indeed

> It's a subclass of Integral, presumably. And normally only builtins.bool is registered with it. But np.bool can be added at the same point you register the other np integral types.

I would rather suggest to keep that Boolean ABC class independent of Integral (see proposal in first post) to let it remain 'pure', i.e. represent logical booleans only. However nothing prevents us to register python bool as a virtual subclass of *both* Integral and Boolean - while np.bool would be registered as a virtual subclass of Boolean only. This would reflect quite well the reality - the fact that python bool is both a Boolean and an Integer, while numpy bool is only a Boolean.

By the way, is there a reason for the name "Integral" (algebraic theory) instead of "Integer" (computer science) ? Would it be practically feasible to add "Integer" as an alias to "Integral" in the numbers package ? 

Sylvain 

-----Message d'origine-----
De : Chris Barker - NOAA Federal [mailto:chris.barker at noaa.gov] 
Envoyé : vendredi 16 février 2018 22:42
À : guido at python.org
Cc : Sylvain MARIE <sylvain.marie at schneider-electric.com>; Python-Ideas <python-ideas at python.org>
Objet : Re: [Python-ideas] Boolean ABC similar to what's provided in the 'numbers' module

Sent from my iPhone
> A thought just occurred to me. Maybe we should just add a Boolean class to numbers?

This makes lots of sense to me.

Bool is a subclass of int — might as well embrace that fact.

-CHB

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________


More information about the Python-ideas mailing list