C API eqivalent of object.__new__

Jacek Generowicz jacek.generowicz at cern.ch
Fri Oct 1 11:41:53 EDT 2004


aleaxit at yahoo.com (Alex Martelli) writes:

> Jacek Generowicz <jacek.generowicz at cern.ch> wrote:
> 
> > Jacek Generowicz <jacek.generowicz at cern.ch> writes:
> > 
> > > How would one write object._new__(SomeType) in the C API ?
> > 
> > PyInstance_NewRaw(PyObject *class, [PyObject* dict])
> > 
> > seems to be the way to do this for classic classes. How would one do
> > it for new-style classes?
> 
> You mean something like:
> PyObject_CallMethod( (PyObject*)&PyBaseObject_Type,
>                                 "__new__", "O", clas);
> ?
>  
> > Also, how would one create a new-style class "dynamically" in the C
> > API? IOW, what's the new-style equivalent of PyClass_New? or, put
> > another way, how would you write
> > 
> >   type(name, (), dict)
> > 
> > in the C API ?
> 
> You mean something like:
> PyObject_CallFunctionObjArgs(
>                           (PyObject*)&PyType_Type,
>                           classname, classbases, classdict,
>                           NULL);
> ?

I was indeed starting to think about PyObject_Call* approaches to
this, but didn't want to go down that path without making sure that I
haven't missed some function that was specifically designed to do it.

If _you_ don't know of one, then I'll take that to mean that I
shouldn't waste more time looking for it :-)

Thanks.



More information about the Python-list mailing list