forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 18
docstrings
stv edited this page Jul 12, 2018
·
1 revision
- Use double-quotes instead of single quotes.
- Treat all docstrings as if they were multi-line.
def foo():
"""
Demonstrate a docstring
"""
pass
def foo():
"""
Demonstrate a docstring
with multiple lines
"""
pass
def foo():
'''
Demonstrate a docstring
'''
pass
def foo():
""" Demonstrate a docstring """
pass
def foo():
""" Demonstrate a docstring
with multiple lines
"""
pass
def foo():
""" Demonstrate a docstring
with multiple lines
"""
pass
From PEP-257:
Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description. The summary line may be used by automatic indexing tools; it is important that it fits on one line and is separated from the rest of the docstring by a blank line.
From PEP-257:
For consistency, always use """triple double quotes""" around docstrings.
From PEP-257:
Triple quotes are used even though the string fits on one line. This makes it easy to later expand it.
Taking this further, we can make it even easier to expand later (and minimize the diff) by always treating docstrings as if they were already multiline.
Consider:
Demonstrate a docstring
+
+ with multiple lines
"""
versus:
def foo():
- """ Demonstrate a docstring """
+ """
+ Demonstrate a docstring
+
+ with multiple lines
+ """
pass
External Resources: