Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'anyway.': 0.04; 'missed': 0.09; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; '(line': 0.16; 'fancy': 0.16; 'new-style': 0.16; 'old-style': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'thanks!!!': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'all,': 0.21; 'import': 0.21; "i've": 0.23; 'seems': 0.23; 'pass': 0.25; 'header :User-Agent:1': 0.26; 'wonder': 0.27; 'header:X-Complaints-To:1': 0.28; 'yes.': 0.29; 'skip:_ 10': 0.29; 'source': 0.29; 'class': 0.29; 'maybe': 0.29; 'expect': 0.31; 'code': 0.31; 'to:addr :python-list': 0.33; 'thanks': 0.34; 'something': 0.35; 'received:org': 0.36; 'created': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'dear': 0.66; 'pytypeobject': 0.84; 'abc': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: RE: metatype Date: Tue, 12 Mar 2013 07:50:21 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p508493c1.dip.t-dialin.net User-Agent: KNode/4.7.3 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363070989 news.xs4all.nl 6936 [2001:888:2000:d::a6]:54010 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41111 shangyu wrote: > Hi dear all, > I have following Python code > class mydict(dict): > def __init__(self): > pass > I wonder how this new type get created . What is the type of metatype in > the following line ? type = (PyTypeObject *)metatype->tp_alloc(metatype, > nslots); (line 2296 of typeobject.c Python2.7.3 source code) > It seems PyDict_Type . If so , how do I expect the tp_alloc will return a > PyTypeObject object ? Maybe I've missed something ? Many thanks!!! > I think I've found it out . For new-style class it's PyType_Type and for > old-style class it's PyClass_Type . Thanks anyway. Yes. You can find that out without resorting to the C API: >>> class A(dict): pass ... >>> type(A) A fancy example: >>> import abc >>> class B: ... __metaclass__ = abc.ABCMeta ... >>> type(B)