VS Code renders markdown fine in mouse hovers - but doesn't render standard docstring formats well

The VS Code Python extension will use markdown that you put into a docstring for intellisense mouse hover information, but this doesn't really meet any of the commonly accepted/used docstring formats for Python. It doesn't properly layout any of those common formats (as of May 2020).

Update (4/2023): Sphinx has been updated to support markdown in docstrings for its auto-code generation, meaning you can put all your docstrings in markdown and they will look good in VS Code hovers and also work with Sphinx

So, your options are:

  1. Stick with one of the major formats that will work with existing Python documentation tools and utilities like Sphinx
  2. Use markdown in your docstrings and look good in VS Code, but be incompatible with most other documentation tools


More Details / Example

The top 3 Python docstring formats are:

  • Google
  • Sphinx
  • NumPY/ReST

VS Code will take ReST format (NumPY style) and properly layout the headers from each section (each item with the line of dashes under it), but in all the formats, the section content is unformatted and munged together with all the linebreaks dropped.

If you use markdown directly in the docstrings, it is supported, but then you aren't meeting the formatting requirements of docstrings for auto documentation frameworks like Sphinx. For example, I started with Sphinx format here and modified it to look better with VS Code's markdown tooltips

def autodoc_test_numpy(self, a: str, b: int = 5, c: Tuple[int, int] = (1, 2)) -> Any:
    """[summary]

    ### Parameters
    1. a : str
        - [description]
    2. *b : int, (default 5)
        - [description]
    3. *c : Tuple[int, int], (default (1, 2))
        - [description]

    ### Returns
    - Any
        - [description]

    Raises
    ------
    - ValueError
        - [description]
    """

Will render like this:

Notice that the final "Raises" section here has the underlining with dashes that makes it a level 1 header (which is the ReST style). Look how big it is! I bumped the other down to h3 by using ### in front of the text instead of underlining it with hyphens on the next line.

Also, note that the type hints in the main function definition (like str in the a: str) render well (even colored) for args and the return type hint, but are not shown for kwargs (e.g. b=5 without the type hint).

Answer from LightCC on Stack Overflow
Top answer
1 of 4
45

VS Code renders markdown fine in mouse hovers - but doesn't render standard docstring formats well

The VS Code Python extension will use markdown that you put into a docstring for intellisense mouse hover information, but this doesn't really meet any of the commonly accepted/used docstring formats for Python. It doesn't properly layout any of those common formats (as of May 2020).

Update (4/2023): Sphinx has been updated to support markdown in docstrings for its auto-code generation, meaning you can put all your docstrings in markdown and they will look good in VS Code hovers and also work with Sphinx

So, your options are:

  1. Stick with one of the major formats that will work with existing Python documentation tools and utilities like Sphinx
  2. Use markdown in your docstrings and look good in VS Code, but be incompatible with most other documentation tools


More Details / Example

The top 3 Python docstring formats are:

  • Google
  • Sphinx
  • NumPY/ReST

VS Code will take ReST format (NumPY style) and properly layout the headers from each section (each item with the line of dashes under it), but in all the formats, the section content is unformatted and munged together with all the linebreaks dropped.

If you use markdown directly in the docstrings, it is supported, but then you aren't meeting the formatting requirements of docstrings for auto documentation frameworks like Sphinx. For example, I started with Sphinx format here and modified it to look better with VS Code's markdown tooltips

def autodoc_test_numpy(self, a: str, b: int = 5, c: Tuple[int, int] = (1, 2)) -> Any:
    """[summary]

    ### Parameters
    1. a : str
        - [description]
    2. *b : int, (default 5)
        - [description]
    3. *c : Tuple[int, int], (default (1, 2))
        - [description]

    ### Returns
    - Any
        - [description]

    Raises
    ------
    - ValueError
        - [description]
    """

Will render like this:

Notice that the final "Raises" section here has the underlining with dashes that makes it a level 1 header (which is the ReST style). Look how big it is! I bumped the other down to h3 by using ### in front of the text instead of underlining it with hyphens on the next line.

Also, note that the type hints in the main function definition (like str in the a: str) render well (even colored) for args and the return type hint, but are not shown for kwargs (e.g. b=5 without the type hint).

2 of 4
10

As far as I know, there is no official format that is supported. The code has a few functions it runs to convert some parts of RST to Markdown to be displayed, but that is pretty much it.

The code that does the conversion can be found here. The tests, which is a good way of seeing some actual examples, can be found here.

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
autoDocstring: VSCode Python Docstring Generator
Extension for Visual Studio Code - Generates python docstrings automatically
Discussions

No More Python Docstring Despair: Highlight Them in VSCode!
What happens when you start a string with a double quote instead of single quotes? More on reddit.com
🌐 r/vscode
8
21
March 12, 2024
Can't generate Python docstring with autoDocstring extension in VS Code when multiline string in the function body - Stack Overflow
To generate documentation with Python Sphinx I have to use a specific docstring format. VS Code extension autoDocstring is capable to generate this specific format, but if the function contains mul... More on stackoverflow.com
🌐 stackoverflow.com
No More Docstring Despair: Highlight Them in VSCode!
This is actually a great idea. Well done. Ideally, this should be built-in in VScode. More on reddit.com
🌐 r/Python
30
103
March 12, 2024
What is the "working" Python docstring style for VS Code tooltips?
I think I see what you mean. It doesn't really answer your question, but here are a couple considerations that can make your life easier in the meantime: I wanted to make the docstrings more legible in the code. I used the extension Highlight to write ugly regexes to match specific characters in a Google-style docstring, to make it more legible, like so . Instead of relying on tooltips, you can rely on another nice feature of VS Code: Peek Definition. It allows you to look to another location in the code in-place. It's a nice way to quickly see what a function does somewhere else in the code. You can bind this operation to a keybind of your liking to do that efficiently. I also recommend using the autoDocstring extension, which works nice. I wrote a custom mustache template to remove types from the Google template, as I rely on the extension sphinx_autodoc_typehints to generate them from my type hints. More on reddit.com
🌐 r/vscode
2
3
March 11, 2020
🌐
Reddit
reddit.com › r/python › no more docstring despair: highlight them in vscode!
r/Python on Reddit: No More Docstring Despair: Highlight Them in VSCode!
March 12, 2024 -

Hey everyone!

I'm excited to share a simple yet effective tool I've developed that's all about enhancing your Python coding experience in VSCode. We all know how Docstrings are crucial for understanding and documenting our Python code, but they often blend into the background, treated as standard comments in VSCode. This can make them harder to read and differentiate from the rest of your code.

That's why I created a Python Docstring Highlighter for VSCode that recognizes the main styles (Google, NumPy, and Sphinx). This extension not only makes your code more readable but also allows you to customize the highlighting to fit your theme, making your coding environment as comfortable and productive as possible.

Whether you're documenting your own project or navigating through others', this extension is designed to make your life easier and your code more accessible. Give it a try and see the difference for yourself!

Source code

Install extension (VSCode)

Looking forward to your feedback and suggestions. Happy coding!

🌐
Medium
leowu507.medium.com › how-to-make-writing-docstrings-quick-and-easy-in-vs-code-e6ddfcd0504d
Efficient Docstring Writing with autoDocstring in VS Code | by Leo Wu | Medium
June 20, 2023 - I’m here to share a tool called autoDocstring and some tips to assist you in writing consistent docstrings more efficiently in VS Code.
🌐
Microsoft Developer Blogs
devblogs.microsoft.com › dev blogs › microsoft for python developers blog › python in visual studio code – november 2024 release
Python in Visual Studio Code - November 2024 Release - Microsoft for Python Developers Blog
November 1, 2024 - The November 2024 release of the Python and Jupyter extensions for Visual Studio Code are now available. This month's updates include docstring template generation with Pylance, Fold/Unfold All Docstrings commands, a variable view with the Native REPL and more!
🌐
GitHub
github.com › microsoft › vscode-python › discussions › 20638
Docstring formatting settings · microsoft/vscode-python · Discussion #20638
microsoft / vscode-python Public forked from DonJayamanne/pythonVSCode ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... Hi all, it seems the default behavior for docstrings on hover has changed, and now basically every method/function seems to show the signature with line breaks.
Author: microsoft
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python Docstring Formats (Styles) and Examples | note.nkmk.me
August 26, 2023 - Holding down shift and repeatedly pressing tab changes the display style. In Visual Studio Code (VSCode) with the Python extension installed, hovering the cursor over the target function shows the docstring in a tooltip.
🌐
Python Engineer
python-engineer.com › posts › vscode-python-setup
My Minimal VS Code Setup for Python - 5 Visual Studio Code Extensions - Python Engineer
Usage: Write a function first, then go to the beginning of the function and type three double quotation marks ("""). Then hit enter, and you get a docstring that already contains the input and return variables.
🌐
Python How Tos
campbell-muscle-lab.github.io › howtos_Python › pages › documentation › best_practices › vscode_docstring_extension › vscode_docstring_extension.html
Visual Studio Docstring Extension - Python How Tos
To automatically insert the docstring with proper formatting, you type three quotes, """ like a normal docstring, then hit Enter to let the extension automatically format the docstring.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
python docstrings - Visual Studio Marketplace
Extension for Visual Studio Code - generate python docstrings for classes and methods
🌐
Reddit
reddit.com › r/vscode › no more python docstring despair: highlight them in vscode!
r/vscode on Reddit: No More Python Docstring Despair: Highlight Them in VSCode!
March 12, 2024 -

Hey everyone!

I'm excited to share a simple yet effective tool I've developed that's all about enhancing your Python coding experience in VSCode. We all know how Docstrings are crucial for understanding and documenting our Python code, but they often blend into the background, treated as standard comments in VSCode. This can make them harder to read and differentiate from the rest of your code.

That's why I created a Python Docstring Highlighter for VSCode that recognizes the main styles (Google, NumPy, and Sphinx). This extension not only makes your code more readable but also allows you to customize the highlighting to fit your theme, making your coding environment as comfortable and productive as possible.

Python Docstring Highlighter Demo (google style)

Whether you're documenting your own project or navigating through others', this extension is designed to make your life easier and your code more accessible. Give it a try and see the difference for yourself!

Source code

Install extension (VSCode)

Looking forward to your feedback and suggestions. Happy coding!

🌐
GitHub
github.com › AZaugg › vscode-python-docstring
GitHub - AZaugg/vscode-python-docstring · GitHub
An inspired vscode extentions for creating python docstring on new functions/methods.
Starred by 4 users
Forked by 2 users
Languages: TypeScript
🌐
Towards Data Science
towardsdatascience.com › home › latest › step by step basics: code autodocumentation
Step by Step Basics: Code Autodocumentation | Towards Data Science
January 24, 2025 - The below code block is a typical example of a Google docstring: ... """Description of the function, class or method etc.Args: varA (str): Description of varA varB (bool): Description of varBReturns: list: Description of returned listRaises: ValueError: Description of raised error""" Top tip. download the 'autoDocstring - Python Docstring Generator' in VS Code to automatically generate a docstring when you type three double quotation marks (i.e.
🌐
Microsoft Developer Blogs
devblogs.microsoft.com › dev blogs › microsoft for python developers blog › python in visual studio code – december 2024 release
Python in Visual Studio Code - December 2024 Release - Microsoft for Python Developers Blog
December 16, 2024 - If you’re interested, you can ... docstring is a string literal that appears right after the definition of a function, method, class, or module used to document the purpose and usage of the code it describes....
🌐
Python Land
python.land › home › language deep dives › python docstring: documenting your code
Python Docstring: Documenting Your Code • Python Land Tutorial
May 10, 2022 - There’s a clear distinction between Python comments and docstrings. A comment is ignored completely by the Python interpreter, while a docstring is an actual string that the interpreter sees. Because we don’t assign the string, it’s considered useless by the interpreter while running the code and is effectively ignored.
🌐
Medium
medium.com › internet-of-technology › how-to-properly-display-tables-in-python-docstrings-in-vs-code-8e334c225f01
Docstring Table Rendering Issues in VS Code | Internet of Technology
August 13, 2024 - This article compares reStructuredText (reST) and Markdown tables in VS code and investigates docstring table rendering issues with reST. Photo by Clément Hélardot on Unsplash. reST is the default markup language for Sphinx, a tool for generating Python documentation.