Why I can’t extend bool in Python?

Guido’s take on it:

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

Reference: http://mail.python.org/pipermail/python-dev/2002-March/020822.html

Leave a Comment