Python23: cannot inherit from bool?

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

"Andrew Thompson" <andrew.thompson at> wrote in message
news:mailman.1042638386.12093.python-list at
> 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
[mailto:python-list-admin at]
> On Behalf Of Robin Becker
> Sent: 15 January 2003 13:28
> To: python-list at
> Subject: Re: Python23: cannot inherit from bool?
> In article <b03kr8$lbili$1 at>, James Kew
> <james.kew at> 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
> --

More information about the Python-list mailing list