[Python-Dev] bool does not want to be subclassed?

Joshua Marshall Joshua.Marshall at mathworks.com
Thu Feb 12 17:29:31 EST 2004


> [Guido]
> 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.)

> [François]
> This is a convincing argument, and enough a reason.  Thanks!  Now, I know why Python refuses! :-)

I don't think I'm convinced; the same argument could be used for integers (if it doesn't make sense to create a sort of boolean which isn't in the set { true, false }, then it doesn't make sense to create a sort of integer which isn't in the set { ..., -2, -1, 0, 1, 2, ... }).  And maybe it doesn't, but this isn't the only reason for subclassing.  Another reason for subclassing is to create items which can act like existing objects, but which have some additional behavior.



More information about the Python-Dev mailing list