How to set docstrings for extensions supporting PyNumberMethods?

2007-03-03 Thread Nick Alexander
Hello,

I am writing a python extension (compiled C code) that defines an
extension type with PyNumberMethods.  Everything works swimmingly,
except I can't deduce a clean way to set the docstring for tp_*
methods.  That is, I always have

type.__long__.__doc__ == 'x.__long__() <==> long(x)'

which a quick glance at the Python 2.5 source shows is the default.

I have found that I can use PyObject_GetAttr and PyWrapperDescrObject
and set the descriptor objects d_base->doc to a char pointer... but I
can't tell if this is safe.  Or the right way to do it.

If I'm on the wrong list, please let me know!
Thanks,
Nick Alexander

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to set docstrings for extensions supporting PyNumberMethods?

2007-03-04 Thread Nick Alexander
On Mar 4, 12:14 am, "Ziga Seilnacht" <[EMAIL PROTECTED]> wrote:
> NickAlexanderwrote:
> > Hello,
>
> > I am writing a python extension (compiled C code) that defines an
> > extension type with PyNumberMethods.  Everything works swimmingly,
> > except I can't deduce a clean way to set the docstring for tp_*
> > methods.  That is, I always have
>
> > type.__long__.__doc__ == 'x.__long__() <==> long(x)'
>
> > which a quick glance at the Python 2.5 source shows is the default.
>
> > I have found that I can use PyObject_GetAttr and PyWrapperDescrObject
> > and set the descriptor objects d_base->doc to a char pointer... but I
> > can't tell if this is safe.  Or the right way to do it.
>
> > If I'm on the wrong list, please let me know!
> > Thanks,
> >NickAlexander
>
> I think that the right way is to add the methods to the tp_methods
> slot and use METH_COEXIST in the PyMethodDef flags field. Example:

Ziga, thanks for an extremely helpful reply.  I'll experiment and post
again if there are issues.

Cheers!
Nick

-- 
http://mail.python.org/mailman/listinfo/python-list