Python23: cannot inherit from bool?

John Roth johnroth at ameritech.net
Wed Jan 15 16:54:57 CET 2003


"Andrew Thompson" <andrew.thompson at ashecastle.com> wrote in message
news:mailman.1042638386.12093.python-list at python.org...
> Inheriting from bool is a clever idea from Smalltalk.
>
> Where true and false subclass the abstract type bool.
>
> This then makes if,and,or,not all very natural to define.
>
> Andrew

Unfortunately, that's not what Python is doing, and the Smalltalk
implementation doesn't map at all well. If I understand you,
true and false are separate classes in Smalltalk. In Python, they
are instances of one class, so they can't have different methods
for the logical operators.

That's a performance restriction. I could hack a normal function
into an instance and expect it to work, but I can't do that with
one of the builtins because the interpreter doesn't look at the
instance dictionary first. It goes right to the class, and looks in
a special table rather than looking in the dictionary.

John Roth

>
> -----Original Message-----
> From: python-list-admin at python.org
[mailto:python-list-admin at python.org]
> On Behalf Of Robin Becker
> Sent: 15 January 2003 13:28
> To: python-list at python.org
> Subject: Re: Python23: cannot inherit from bool?
>
>
> In article <b03kr8$lbili$1 at ID-71831.news.dfncis.de>, James Kew
> <james.kew at btinternet.com> writes
> >FrankS wrote:
> >> It seems that 2.3 doesn't allow you to inherit from bool:
> >
> >I'm not qualified to comment on why it's not allowed, but out of
> >interest: why might you want to inherit from bool?
> >
> .... don't know the answer to that one, but is the non inheritance
> property available to ordinary python if yes we could create leaf
> classes.
> --
> Robin Becker
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>






More information about the Python-list mailing list