adding a docstring to an instancemethod

J

jelle

Hi,

I'm working on documenting wrapped C++ methods.
The thing is that I'd like to add docstrings to a method, but python
won't allow me to:
TypeError: attribute '__doc__' of 'instancemethod' objects is not
writable

What would be an easy way to do so? I'd like to overload the .__doc__,
rather than wrapping it in a class.

Cheers,

-jelle
 
G

Gabriel Genellina

I'm working on documenting wrapped C++ methods.
The thing is that I'd like to add docstrings to a method, but python
won't allow me to:
TypeError: attribute '__doc__' of 'instancemethod' objects is not
writable

Set the __doc__ on the *function* from which you build the instance method.
 
J

jelle

Set the __doc__ on the *function* from which you build the instance method.

Thanks for you reply Gabriel,
Though setting the docstring to the functions wouldn't be an option
for me.
The thing is that I have a

wrappedCppModule.Class.Method I'd like to give a docstring, so there's
no prior function to refer to.

Thanks,

-jelle
 
J

jelle

Hi Gabriella,

thanks for pointing me in the right direction:
eo.eoTruncatedSelectOne.setup.im_func.func_doc = 'method string goes
here'
works beautifully!

cheers,

-jelle
 
S

Steven D'Aprano

Twice in a week... I'll have to revise my own masculinity...

You need to spit and fart a lot in your posts, and talk about sport.

Either that, or change your name to Sylar and eat people's brains.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top