docstring !!
!1
• @cocodrips
• Jenkins 

→ 

→AI
• :

PyDataTokyo 

2
1. docstring
2. docstring
3. docstring
. docstring
docstring
• Python
4
def f(arg1):
""" """
pass
docstring
5
>>> help(f)
Help on function f:
f(arg1)
• docstring help 

docstring
• Jupyter Notebook ? 

help
6
docstring
•
• 

• type 

IDE (IDE )
•
7
docstring
9
def func(arg1, arg2):
“”" *1 *
0
Parameters
----------
1 :
1
2 :
2
Returns
-------
"""
10
def func(arg1, arg2):
“”" *1 *
0
Parameters
----------
1 :
1
2 :
2
Returns
-------
"""
1
※
doc
11
•
def func(arg1, arg2):
“”” ””"
12
• TypeHint
def func(arg1: int, arg2: str) -> bool:
"""
Parameters
----------
1 : 1
2 : 2
"""
13
• Class docstring
class Hello:
"""
"""
14
• module(.py ) docstring -
"""
"""
docstring
3
• ReStructuredText
• NumPy Style
• Google Style
15
docstring - ReStructuredText
16
def func(arg1, arg2):
"""
:param arg1: 1
:type arg1: 1
:param arg2: 2
:type arg2: 2
:return:
:rtype:
"""
docstring - NumPy style
17
def func(arg1, arg2):
"""
Parameters
----------
arg1 : 1
1
arg2 : 2
2
Returns
-------
"""
• 

• 

•
docstring - Google Style
18
def func(arg1, arg2):
"""
Args:
arg1 ( 1 ): 1
arg2 ( 2 ): 2
Returns:
:
"""
•
•
19
• ReStructuredText
•
• NumPy Style
•
•
• Google Style
•
•
VS Code: autoDocsring
20
PyCharm:
21
docstring
Sphinx
23
•知的で美しいドキュメント 

( )
• Sphinx Web 

Flask
24
$ git clone git@github.com:pallets/flask.git
# 依存ライブラリのインストール
$ python seup.py install
25
sphinx-apidoc import 



!!!
sphinx-apidoc
26
# 設定ファイルを作る & ドキュメントの雛形を生成
$ sphinx-apidoc -F -a -o ./doc ./flask
doc
├── Makefile
├── _build
├── _static
├── _templates
├── conf.py
├── flask.rst
必要に応じて
設定ファイルを書き換え
!27
flask package
=============
…
Submodules
----------
flask.app module
----------------
.. automodule:: flask.app
:members:
:undoc-members:
:show-inheritance:
flask.app
flask.app
/
28
$ cd doc
$ make html
$ open _build/html/index.html
!29
^ω^
30
…
• Quick Start
•
•
32


33
34
: docstring
• 

(Google/Numpy)
• 

docstring ?
• docstring PR 

↑↑↑↑↑↑ ↑↑↑↑↑↑
36
doc-cov
•
37
$ doccov flask/flask -fmc
class 38 / 45 84.44%
module 19 / 19 100.00%
function 356 / 504 70.63%
doc-cov
Pull request
38
# CI内で以下を実行
$ doccov <project> -fmc --output csv > doccov.csv
$ doccov-report doccov.csv
Pull Request / Issue

39
$ pip install doc-cov

Docstringを書こう!