-
Notifications
You must be signed in to change notification settings - Fork 0
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 canstrip()
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 thepass
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
"""
- Home
- Structural Naming Conventions
- Format Conventions
- Code Naming Conventions
- Inheritance
- Access Modifiers
- Importation
- Functions and Methods
- Documentation
- Resources