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


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

RE: metatype

Started byPeter Otten <__peter__@web.de>
First post2013-03-12 07:50 +0100
Last post2013-03-12 07:50 +0100
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: metatype Peter Otten <__peter__@web.de> - 2013-03-12 07:50 +0100

#41111 — RE: metatype

FromPeter Otten <__peter__@web.de>
Date2013-03-12 07:50 +0100
SubjectRE: metatype
Message-ID<mailman.3219.1363070989.2939.python-list@python.org>
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)
<type 'type'>

A fancy example:

>>> import abc
>>> class B:
...     __metaclass__ = abc.ABCMeta
... 
>>> type(B)
<class 'abc.ABCMeta'>

[toc] | [standalone]


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


csiph-web