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

Python - convert docstring styles

up::[[MOC_python]] When refactoring 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.


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). -


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

run from the command line:

pyment    # will generate a patch
pyment -w  # will overwrite the file

to apply specific style (here - google style):

pyment -w -o google

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

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


Reference documentation