subclassable types

Sven svenito at gmail.com
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:
http://mail.python.org/pipermail/python-dev/2002-March/020822.html
http://mail.python.org/pipermail/python-dev/2004-February/042537.html

specifically:

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.

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 biologie.uni-freiburg.de> 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!
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
./Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130222/215793c6/attachment.html>


More information about the Python-list mailing list