Docstrings
Function and Methods
1.
함수는 (1)외부에 보이지않거나, (2)매우 짧거나, (3)명확한 경우를 제외하고는 Docstring을 가져야 한다.
2.
Docstring은 함수의 코드를 직접 읽지 않고도, 사용하기에 충분한 정보를 제공해야 한다.
3.
명령형보다 서술형이어야 한다.
4.
한 줄로 설명 가능하면 하되, 아닐경우 아래의 Section을 따른다.
def fetch_smalltable_rows(table_handle: smalltable.Table,
keys: Sequence[Union[bytes, str]],
require_all_keys: bool= False,
)-> Mapping[bytes, Tuple[str, ...]]:
"""Fetches rows from a Smalltable.
Retrieves rows pertaining to the given keys from the Table instance
represented by table_handle. String keys will be UTF-8 encoded.
Args:
table_handle: An open smalltable.Table instance.
keys: A sequence of strings representing the key of each table
row to fetch. String keys will be UTF-8 encoded.
require_all_keys: If True only rows with values set for all keys will be
returned.
Returns:
A dict mapping keys to the corresponding table row data
fetched. Each row is represented as a tuple of strings. For
example:
{b'Serak': ('Rigel VII', 'Preparer'),
b'Zim': ('Irk', 'Invader'),
b'Lrrr': ('Omicron Persei 8', 'Emperor')}
Returned keys are always bytes. If a key from the keys argument is
missing from the dictionary, then that row was not found in the
table (and require_all_keys must have been False).
Raises:
IOError: An error occurred accessing the smalltable.
"""
Python
복사
Class
1.
클래스 정의 아래에 Docstring을 넣어야 한다.
2.
Public Attribute가 있는 경우, Attribute 섹션을 만들고 Function의 Args 처럼 작성한다
class SampleClass:
"""Summary of class here.
Longer class information....
Longer class information....
Attributes:
likes_spam: A boolean indicating if we like SPAM or not.
eggs: An integer count of the eggs we have laid.
"""
def __init__(self, likes_spam: bool= False):
"""Inits SampleClass with blah."""
self.likes_spam= likes_spam
self.eggs= 0
def public_method(self):
"""Performs operation blah."""
Python
복사