Creating a new object of your own type in a C extension.

H

Heiko Wundram

Hi all!

Just a small question concerning type creation in a C object: If I create a
class which is overridable, I'd like to have that class create objects of
it's overridden type, e.g. I have a class X which is implemented in C, which
is wrapped in Python by a class Y, now I initialize a Y class, and call a
member of X on that class, and I'd like the member of X to return an object
of class Y. What is a correct way of doing this? I've not found any nice
implementation hints in the documentation...

1) PyObject_New(Xstruct, self->ob_type (which should point to the type of Y))
2) self->ob_type->tp_new(self->ob_type,NULL,NULL)
3) anything else?

I don't see any of this being used in the Python object classes (e.g.
overridden classes of int return int when e.g. __add__ is called, etc.).

Thanks for any help!

Heiko.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top