questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__
amirouche.boubekki at gmail.com
Tue Aug 23 22:13:40 CEST 2011
On Aug 22, 1:57 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> The relationship between type and object is somewhat special, and needs to
> be bootstrapped by the CPython virtual machine.
Since you are talking about CPython, I'm wondering how it is
bootstraped since you can easly reference PyType in PyObject that part
is not hard.
> > 2) type is its own metaclass : type(type) is type ?
> Yes. Another bit of bootstrapping that the compiler does.
self reference is easy same as referencing PyType from PyObject and
PyObject from PyType.
> > 5) type(any_object) == last_metaclass_..., which is, most of the time,
> > type ?
> I'm not sure what you mean by "last_metaclass". But no. The type of an
> object is its class:
see this code for example proove my point:
def __new__(cls, *args, **kwargs):
return type.__new__(cls, *args, **kwargs) # see (¤)
def __new___(cls, *args, **kwargs):
return meta_a.__new__(cls, *args, **kwargs) # same as above
__metaclass__ = meta_a
__metaclass__ = meta_b
type(ClassWithTypeMetaA) == meta_a
type(ClassWithTypeMetaB) == meta_b
[¤] super call doesn't work here, anyone can say why ?
More information about the Python-list