Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bool': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; '4:35': 0.16; 'also:': 0.16; 'builtins.': 0.16; 'message- id:@post.gmane.org': 0.16; 'range,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'set,': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'issue.': 0.20; 'all,': 0.21; 'doc': 0.22; 'url:bugs': 0.24; 'header:User-Agent:1': 0.26; 'wondering': 0.26; 'am,': 0.27; 'rules': 0.27; 'header:X -Complaints-To:1': 0.28; 'received:132': 0.29; 'writes:': 0.29; 'this.': 0.29; 'classes': 0.30; 'url:python': 0.32; 'not.': 0.32; 'int': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'built- in': 0.35; 'similar': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'charset:us-ascii': 0.36; 'why': 0.37; 'ones': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'first': 0.61; 'dear': 0.66 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: Re: subclassable types Date: Sun, 24 Feb 2013 16:23:09 +0000 (UTC) References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 132.230.1.31 (Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361723005 news.xs4all.nl 6922 [2001:888:2000:d::a6]:50972 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39754 Terry Reedy 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: of these range, memoryview, slice and bool are the only ones in builtins. Just thought it might be interesting.