Re: subclassable types
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 <
> 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!
|All times are GMT. The time now is 09:09 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.