スフィンクスへの "タイプヒントでの前方参照のクラス定義はどこですか?
タイプヒントの前方参照によって型が定義されている、紛失したパラメータ(Sphinxドキュメント)を回避する方法はありますか?Sphinxへの "タイプヒントの前方参照のクラス定義はどこですか?"
私は、私のPythonプログラムのドキュメントを書くためにsphinx-apidocを使用します。
私は前方に、このようPEP 484で定義されているタイプのヒントのリファレンスを使用しています:
# In file A/A.py
class A:
def a(self, param: 'MyClass') -> None:
"""docstring here"""
pass
MyClassのは、円形の輸入を回避するためにインポートされません。もちろん、実行時に型ヒントが無視されるので、プログラムは正常に動作します。
sphinx-apidocを実行してhtmlを作成すると、次の警告(名前「MyClass」が定義されていません)が表示されます。生成されたHTMLは、このようなパラメータを有する、(円形の輸入なし)輸入MyClassのに関連して
A module
class A
a() -> None
docstring here
:生成されたHTML、方法において
$ sphinx-apidoc -f -o doc .
Creating file doc/A.rst
$ make html
...
reading sources... [100%] main
path/to/A/A.rst:XX: WARNING: error while formatting arguments for A.A.a: name 'MyClass' is not defined
looking for now-outdated files... none found
...
build succeeded, 1 warnings.
Build finished. The HTML pages are in _build/html.
「」は、このようなパラメータを指定しません。
A module
class A
a(param: MyClass) -> None
docstring here
私の環境:
$ python3 --version
Python 3.5.2
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 freeze | grep Sphinx
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Sphinx==1.5.2
ありがとうございます。 [Issue#3494](https://github.com/sphinx-doc/sphinx/issues/3494)を意味する場合があります。私は固定版を試してみる。 – Moco