Moving docstrings from C to Python
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
Hi, Travis recently advertised the add_docstring and add_newdoc functions, which are used to add documentation to functions written in C. This brings the advantage that you don't have to recompile everytime you change a docstrings, and also that the docstrings are much simpler to format (no more "\n\" tokens all over the place). I took all the docstrings from numpy.core.src.multiarray and formatted them to be used with add_docstring. I have two questions: Would anyone mind if the change was made? If not, where should they go? (numpy/add_newdocs.py or numpy/core/something) Thanks for the feedback. Stéfan
![](https://secure.gravatar.com/avatar/837d314801b4f1400d6eabc767ca2cac.jpg?s=120&d=mm&r=g)
On 7/28/06, Stefan van der Walt <stefan@sun.ac.za> wrote:
Would anyone mind if the change was made? If not, where should they go? (numpy/add_newdocs.py or numpy/core/something)
Another +1 for numpy/add_newdocs.py and a suggestion: check for Py_OptimizeFlag > 1 in add_newdoc so that docstrings are not loaded if python is invoked with -OO option. This will improve import numpy time and reduce the memory footprint. I'll make the change if no one objects.
![](https://secure.gravatar.com/avatar/67eadceb08f909ead3915fc9d9145a7d.jpg?s=120&d=mm&r=g)
I started to do the same with array methods, but before I spend too much time on it, I'd like to be sure I'm doing the right thing. 1. In add_newdocs.py, add from numpy.core import ndarray 2. then add an entry for each method, eg add_docstring(ndarray.var, """a.var(axis=None, dtype=None) Return the variance, a measure of the spread of a distribution. The variance is the average of the squared deviations from the mean, i.e. var = mean((x - x.mean())**2). See also: std """) 3. in arraymethods.c, delete static char doc_var[] = ... remove doc_var in {"var", (PyCFunction)array_variance, METH_VARARGS|METH_KEYWORDS, doc_var}, David 2006/7/28, Sasha <ndarray@mac.com>:
![](https://secure.gravatar.com/avatar/837d314801b4f1400d6eabc767ca2cac.jpg?s=120&d=mm&r=g)
On 7/28/06, Stefan van der Walt <stefan@sun.ac.za> wrote:
Would anyone mind if the change was made? If not, where should they go? (numpy/add_newdocs.py or numpy/core/something)
Another +1 for numpy/add_newdocs.py and a suggestion: check for Py_OptimizeFlag > 1 in add_newdoc so that docstrings are not loaded if python is invoked with -OO option. This will improve import numpy time and reduce the memory footprint. I'll make the change if no one objects.
![](https://secure.gravatar.com/avatar/67eadceb08f909ead3915fc9d9145a7d.jpg?s=120&d=mm&r=g)
I started to do the same with array methods, but before I spend too much time on it, I'd like to be sure I'm doing the right thing. 1. In add_newdocs.py, add from numpy.core import ndarray 2. then add an entry for each method, eg add_docstring(ndarray.var, """a.var(axis=None, dtype=None) Return the variance, a measure of the spread of a distribution. The variance is the average of the squared deviations from the mean, i.e. var = mean((x - x.mean())**2). See also: std """) 3. in arraymethods.c, delete static char doc_var[] = ... remove doc_var in {"var", (PyCFunction)array_variance, METH_VARARGS|METH_KEYWORDS, doc_var}, David 2006/7/28, Sasha <ndarray@mac.com>:
participants (3)
-
David Huard
-
Sasha
-
Stefan van der Walt