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

Guido van Rossum guido at python.org
Mon Feb 19 17:33:06 EST 2018


On Mon, Feb 19, 2018 at 5:58 AM, Sylvain MARIE <
sylvain.marie at schneider-electric.com> wrote:

> > 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.
>

OK, that could work. At this point I think you should just file an issue on
bugs.python.org (but since Python 3.7 is in feature freeze, expect this to
be put on the 3.8 track).


> 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 ?
>

Hm, perhaps Integral is an adjective, just like Boolean? Though it's also
possible that it was simply a mistake. In general I don't like adding
aliases for different spellings -- it violates TOOWTDI. If we decide that
this really was a mistake we should go ahead and make Integer the
recommended way and define Integral as an alias for backwards compatibility.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180219/5de7c8fb/attachment.html>


More information about the Python-ideas mailing list