Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: subclassable types

Reply
Thread Tools

Re: subclassable types

 
 
Wolfgang Maier
Guest
Posts: n/a
 
      02-24-2013
Terry Reedy <tjreedy <at> udel.edu> writes:

>
> On 2/22/2013 4:35 AM, Wolfgang Maier 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?

>
> You are not the first to ask about this. I opened a doc issue.
> http://bugs.python.org/issue17279
>


Thanks, Terry,
using the __flags__ & (1 << 10) trick from Daniel, I did something similar to
what you just added to the doc issue.
The complete list of types classes that *cannot* be subclassed is:

<class 'builtin_function_or_method'>
<class 'code'>
<class 'frame'>
<class 'function'>
<class 'generator'>
<class 'getset_descriptor'>
<class 'function'>
<class 'mappingproxy'>
<class 'member_descriptor'>
<class 'method'>
<class 'traceback'>
<class 'range'>
<class 'memoryview'>
<class 'slice'>
<class 'bool'>

of these range, memoryview, slice and bool are the only ones in builtins.

Just thought it might be interesting.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: subclassable types Wolfgang Maier Python 0 02-24-2013 04:38 PM
Re: subclassable types Terry Reedy Python 0 02-22-2013 10:10 PM
subclassable types Wolfgang Maier Python 1 02-22-2013 10:54 AM
Re: subclassable types Wolfgang Maier Python 0 02-22-2013 10:00 AM
Re: subclassable types Sven Python 0 02-22-2013 09:54 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57