Ok, it turns out this is possible using numpy.add_docstring()
the caveat is that there must be no previous docstring in the object.
Remember: this is only for adding docstrings to compiled extension
module objects at runtime.
Here is a small contrived example (untested):
#---------------------
# decorator.py
#---------------------
import numpy as np
class DocDeco(object):
def __init__(self, doc):
self.doc = str(doc)
def __call__(self, func):
np.add_docstring(func, self.doc)
return func
docdeco = DocDeco
#----------------------
# foo.py
#----------------------
from decorator import docdeco
@docdeco('''docstring goes here''')
def bar():
pass
On Thu, Oct 29, 2009 at 1:32 PM, Chris Colbert <[email protected]> wrote:
> Hi,
>
> I didn't get a response on Cython-users, so i thought I might try here.
>
> I tried modifying the docstrings of cythonized "def" functions via a
> function decorator.
>
> While it passes cython compilation, I get a run-time error that says
> the docstring cannot be modified in place.
>
> Is there a special cython decorator that will allow me to do this, or
> a compile time option that will run my decorator, and generate the new
> docstring before compiling?
>
> Cheers!
>
> Chris
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev