[C++-sig] Re: accessing the python type system

Stefan Seefeld seefeld at sympatico.ca
Thu May 29 17:17:08 CEST 2003


Hi David,

David Abrahams wrote:

>>which means you would be able to hold a boost::python::type
>>describing another boost::python::type's type (i.e.  the result of
>>'type(type([]))'.
>>
>>What do you want to copy here ?
> 
> 
> I don't want to copy anything.  I have no choice; type(type(x)) calls
> type's copy constructor.  I hope that's clear by now.

'type(x)' is a python expression, right ? The equivalent in C is

PyObject *the_type = PyObject_Type(the_object);

so your statement seems to imply that there already is some C++ wrapper
code encapsulating a call to PyObject_Type, and resulting in some class'
copy constructor to be called. Where can I find that ?

I was assuming that the C++ API would provide a function somewhat
similar to

object type(const object &o)
{
   return object(borrowed(PyObject_Type(o.ptr())));
}

or, with a suitable 'type' class defined,

type get_type(const object &o)
{
   return type(borrowed(PyObject_Type(o.ptr())));
}

in which case there is no copy constructor anywhere.


>>Or in diagram form:
>>
>>  py_object       ->       py_type
>>     ^                       ^
>>     |                       |
>>python::object        python::type
> 
> 
> 
> What are those things on the first line of the diagram?

the actual python objects (of type 'PyObject').

>     print 'class:',type(x)
>     print 'metaclass:',type(type(x))
>     print 'metametaclass:',type(type(type(x)))

fine, the last line tells me that the 'metametaclass' is a 'type'.
Applying the 'type' operator to that still returns 'type'. It's just
one level higher up than what I described. So what ?

All I was trying to get at is that a way to look at this is as a
single rooted tree, where each parent node is the 'metaclass' of its
respective child nodes.

>>What am I missing ?
> 
> 
> Seems like just about everything <wink>
> But don't feel bad; nobody understands me.

Ok, still trying...;-)

Regards,
		Stefan






More information about the Cplusplus-sig mailing list