Weitere ähnliche Inhalte
Ähnlich wie チームメイトのためにdocstringを書こう! pyconjp2019 (20)
Kürzlich hochgeladen (20)
チームメイトのためにdocstringを書こう! pyconjp2019
- 11. 11
def func(arg1, arg2):
“”" 1
0
:param arg1: arg1
:type arg1: int #arg1
:param arg2: arg2
:type arg2: str #arg2
:rtype: bool #
:return:
"""
- 17. X
def func(arg1: , arg2: ): ->
"""
:param arg1: 1
:param arg2: 2
:return:
"""
ReStructuredText - TypeHints
- 19. NumPy style - TypeHints
X
def func(arg1: , arg2: ) -> :
"""
Parameters
----------
arg1 :
1
arg2 :
2
Returns
-------
"""
- 24. 22
def func(arg1: , arg2: ): ->
"""
:param arg1: 1
:param arg2: 2
:return:
"""
ReStructuredText - TypeHints
- 30. class Person:
""" """
def __init__(self, age: int, name: str):
self.age = age
self.name = name
def rest_doc_sample(age: int, name: str) -> Person:
"""Person
:param age:
:param name:
:return: Person
"""
# ...
return Person(age, name)
28
sample_package/simple_rest.py
- 31. $ pip install Sphinx sphinx-autodoc-typehints
# 依存ライブラリのインストール
$ python setup.py install
X
sphinx-apidoc import
- 32. sphinx-apidoc
29
# 設定ファイルを作る & ドキュメントの雛形を生成
$ sphinx-apidoc -F -a -o ./doc ./sample_package
doc
├── Makefile
├── _build
├── _static
├── _templates
├── conf.py
├── index.rst
設定ファイル
• Extensionsに以下を追加
• sphinx_autodoc_typehints
• テーマを変更
• sphinx_rtd_theme
• Numpy/Google Styleを
採用する場合は拡張が必要