Those are the Sphinx style doc strings.
Python has some strong opinions about doc strings, see PEP257.
Here is a full description of all of the doc string types in Python: What is the standard Python docstring format?
Answer from townie on Stack OverflowChange docstring style for a project's entire codebase
What style does PyCharm / IntelliJ use for Python docstrings? - Stack Overflow
Documenting Python parameters in docstring using PyCharm - Stack Overflow
python - Custom PyCharm docstring stubs (i.e. for google docstring or numpydoc formats) - Stack Overflow
Videos
Hi Everyone,
I was looking at my code and realized the default docstring isn't my type. I have pretty much all my classes/methods documented in that type. I'm wondering is there any way to change the docstring type (e.g: numpy/google) for each module/class/function in my project automatically.
Would really appreciate, thanks in advance :D
Those are the Sphinx style doc strings.
Python has some strong opinions about doc strings, see PEP257.
Here is a full description of all of the doc string types in Python: What is the standard Python docstring format?
Found this in townie's link:
https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
I'm pretty sure restructured text is the default in PyCharm 2024.2
Have you checked Settings... - Tools - Python integrated tools - Docstring format? You can choose the parsing style.
You can choose from:
- Plain
- Epytext
- reStructuredText
- Numpy
Copied straight from Pycharm: Auto generate `:type param:` field in docstring:
Per the documentation:
If configured, the documentation comment stubs can be generated with
typeandrtypetags.
Following the link:
...
- In the Smart Keys page, select the check box Insert 'type' and 'rtype' to the documentation comment stub.
Once you have done this, put the cursor in a parameter name in the definition, activate the Smart Keys feature (Alt+Enter, by default) and select Specify type for reference in docstring. This will insert the appropriate comment line . Similarly you can put the cursor in the function/method name and select Specify return type in docstring.
So now if you type """ after a function declaration it creates them automatically for you:
def funct(a, b, c):
"""
:param a:
:type a:
:param b:
:type b:
:param c:
:type c:
:return:
:rtype:
"""
With PyCharm 5.0 we finally got to select Google and NumPy Style Python Docstrings templates.
It is also mentioned in the whatsnew section for PyCharm 5.0.
How to change the Docstring Format:
File --> Settings --> Tools --> Python Integrated Tools
There you can choose from the available Docstrings formats:
Plain, Epytext, reStructuredText, NumPy, Google
As pointed out by jstol: for Mac users, this is under
PyCharm -> Preferences -> Tools -> Python Integrated Tools.
As CrazyCoder mentions, its a ticket. Right now, you can only use EpyType and reStructuredText.
At the time of this writing, it is not possible. Several tickets have been submitted over the past several years requesting this feature, presumably it is being worked on.
https://youtrack.jetbrains.com/issue/PY-33833
https://youtrack.jetbrains.com/issue/PY-20243
In the short run, if you need to convert previous projects from the default, you can find the setting is stored in the ".idea/MYPROJECT.iml" file:
<component name="PyDocumentationSettings">
<option name="myDocStringFormat" value="Google" />
</component>
By default, there is no PyDocumentationSettings component, so you'll need to add it. In Linux, you could run the following (very hackish) code in terminal to change all projects in any subdirectory:
new_docstring=' <component name="PyDocumentationSettings">\n <option name="myDocStringFormat" value="Google" />\n </component>\n</module>'
find . -type f -name '*.iml' -print0 | xargs -0 sed -i "s|</module>|$new_docstring|g"
If you simply wanted to go from e.g. Numpy to Google, you might just use:
find . -type f -name '*.iml' -print0 | xargs -0 sed -i "s|Numpy|Google|g"
This isn't possible to do at the moment. Please submit a feature request about it to https://youtrack.jetbrains.com/issues/PY
EDIT: The following ticket (mentioned below) is now in In Progress status https://youtrack.jetbrains.com/issue/PY-20243. According to Fix versions field, it should be implemented in 2019.3 version.