2021-09-29    Share on: Twitter | Facebook | HackerNews | Reddit

Python - Convert Docstring Styles

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