[Python-ideas] IntFlags

Neil Girdhar mistersheik at gmail.com
Mon Mar 9 15:00:20 CET 2015


People have been discussing bool since it was introduced.  Many people have
proposed that bool should not subclass int exactly for this reason (the
Liskov substitution principle), but unfortunately bool evolved from int in
Python 2.2.1 (I think?) when there was already a lot of code using int to
implement Boolean variables with constants like False, True = 0, 1.  In
order not to break too much code, it was decided to allow bool to inherit
from int.  The inheritance of bool from int is not a good precedent when
making inheritance decisions in the future.

On Mon, Mar 9, 2015 at 9:49 AM, <random832 at fastmail.us> wrote:

> On Sun, Mar 8, 2015, at 05:45, Neil Girdhar wrote:
> > If flags were conceptually subtypes of int, then you should be able to do
> > things like:
> >
> > flags ** 7
> >
> > or
> >
> > flags // 91
>
> *cough* bool *cough*
>
> >
> > Do you agree that this is totally meaningless?  There is no "is a"
> > relationship between Flags and int.  There is a conversion between the
> > conceptual mapping that is a Flags object to int for the sole purpose of
> > calling into APIs.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/L5KfCEXFaII/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150309/11a5a4d5/attachment-0001.html>


More information about the Python-ideas mailing list