Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39754 > unrolled thread

Re: subclassable types

Started byWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
First post2013-02-24 16:23 +0000
Last post2013-02-24 16:23 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: subclassable types Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-02-24 16:23 +0000

#39754 — Re: subclassable types

FromWolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Date2013-02-24 16:23 +0000
SubjectRe: subclassable types
Message-ID<mailman.2411.1361723005.2939.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web