September 29, 2021    Share on: Twitter | Facebook | HackerNews | Reddit

Python convert docstring styles

When refacoring the project one might want to change docstring style e.g. from numpy-style to google-style. At this point tool like Pyment comes in handy.

Pyment

Currently, the managed styles in input/output are - javadoc, - one variant of reST (re-Structured Text, used by Sphinx), - numpydoc, - google docstrings, - groups (other grouped style). -

Usage:

you can either apply changes immediately or generate patch (review the path and then apply)

run from the command line:

pyment  myfile.py    # will generate a patch
pyment -w myfile.py  # will overwrite the file

to apply specific style (here - google style):

pyment -w -o google myfile.py

Input/output docstring style parameters: “javadoc”, “reST”, “numpydoc”, “google” (default is “reST”). The input can be also auto for style autodetection.

You might want to limit opertation to only coversion by using option -t, --convert. With this option existing docstrings will be converted but Pyment won’t create missing ones.

References:

Reference documentation2021-10-18