Skip to content

Docstrings

Vinicius Reif Biavatti edited this page Jul 25, 2022 · 2 revisions
  • Use double quote "" for docstrings
  • Always finish the line with period .
  • Always break the first and the end line """\n<doc>\n""". This makes better to edit the docstring. If you want to process the docstring in your code, you can strip() the content to remove the break lines.
  • Try to always use docstrings to document your code for modules, functions, methods and classes
  • Use only relevant content in docstrings. If you don't need to document the parameters of a function for example, don't do it.
  • If you use docstring for an empty class, function or method, don't use ellipses ... or the pass keyword. It is not necessary
  • Do not create blank lines between the documented resource and the docstring

You can use the Docstring Template to facilitate the creation of the docstring

✅ Do

"""
Module description.
"""


def function() -> None:
    """
    Function description.
    """


class Person:
    """
    Class description.
    """

    def method(self) -> None:
        """
        Method description.
        """

❌ Don't

def function() -> None:
    """Function description."""

def function() -> None:
    """Function description.
    """

def function() -> None:  # Without line period
    """
    Function description
    """

def function() -> None:  # Blank line between the resource and the docstring

    """
    Function description
    """
Clone this wiki locally