subclassable types

Sven svenito at
Fri Feb 22 10:54:42 CET 2013

I believe it's a matter of choice by BDFL when it comes to bool. These
might answer your question:


I thought about this last night, and realized that you shouldn't be
allowed to subclass bool at all!  A subclass would only be useful when
it has instances, but the mere existance of an instance of a subclass
of bool would break the invariant that True and False are the only
instances of bool!  (An instance of a subclass of C is also an
instance of C.)  I think it's important not to provide a backdoor to
create additional bool instances, so I think bool should not be

as for range, that's not a type but a built in function (do a print range)

I would suggest that instead of using introspection you could handle
the exception TypeError that is thrown.

On 22 February 2013 09:35, Wolfgang Maier <
wolfgang.maier at> wrote:

> Dear all,
> I am wondering what the rules are that determine whether a built-in type is
> subclassable or not.
> As examples, why can you base your classes on int or set,
> but not on bool or range?
> Also: can you use introspection to find out whether a type is valid as a
> base type?
> Thanks for your help!
> --

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list