我试图记录用于Python的有趣运行时类型检查器的公共API。我完全失败了。狮身人面像的autodoc
扩展找不到标准的纯Python CPython模块,这些模块既保证存在,又微不足道。但事实却是如此。
因此,这个问题与关于这一专题的每一个其他问题都是不同的。正如我手动注入到print()
中的此项目的Sphinx配置演示了语句一样,狮身人面像的运行时sys.path
是正确建立的,并且应该会产生工作。
autodoc
无视理智,无法解析对甚至是标准模块的交叉引用:
$ sphinx-build -M html doc/source/ doc/build/ -W -j auto --keep-going -n -a
Running Sphinx v4.4.0
sys.path (from "doc/source/conf.py"): ['/usr/lib/python-exec/python3.8', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/usr/lib/python3.8/site-packages', '/home/leycec/py/beartype']
loading pickled environment... done
[autosummary] generating autosummary for: changes.rst, index.rst, reference.rst, tutorial.rst
building [mo]: all of 0 po files
building [html]: all source files
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
preparing documents... done
/usr/lib/python3.8/site-packages/beartype/__init__.py:docstring of beartype:3: WARNING: py:mod reference target not found: beartype.meta
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:class reference target not found: beartype._data.datatyping.BeartypeableT
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:class reference target not found: beartype._data.datatyping.BeartypeableT
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:class reference target not found: beartype._data.datatyping.BeartypeableT
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:class reference target not found: BeartypeableT
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:class reference target not found: BeartypeConf
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:class reference target not found: optional
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:class reference target not found: BeartypeReturn
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:exc reference target not found: BeartypeConfException
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:68: WARNING: py:class reference target not found: BeartypeConf
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:exc reference target not found: BeartypeDecorHintException
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:69: WARNING: py:mod reference target not found: typing
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:exc reference target not found: BeartypeDecorHintPep563Exception
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:exc reference target not found: BeartypeDecorParamNameException
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:exc reference target not found: BeartypeDecorWrappeeException
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:: WARNING: py:exc reference target not found: BeartypeDecorWrapperException
waiting for workers...
generating indices... genindex py-modindex done
highlighting module code... [100%] beartype._decor.cache.cachedecor
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build finished with problems, 16 warnings.
忽略上面的所有内容,除了对autodoc
未能找到标准typing
模块的警告:
/usr/lib/python3.8/site-packages/beartype/_decor/cache/cachedecor.py:docstring of beartype._decor.cache.cachedecor.beartype:69: WARNING: py:mod reference target not found: typing
"/usr/lib/python3.8"
驻留在sys.path
中。"/usr/lib/python3.8/typing.py"
是存在的,它确实必须存在。然而,autodoc
却什么也找不到。在这里插入双面罩模因。
我越来越怀疑autodoc
是地狱Incarnate。我们大多数人都已经知道了。其余的人可以通过我微弱的天赋之外的奥术魔法,迫使狮身人面像屈服于他们背信弃义的意志。我是前一类的。
Tangentially:有什么可行的替代autodoc
的方法吗?我可以立即把它变成一个假象,不需要手动记录原始狮身人面像特定的reStructuredText文件中的所有内容(这是不可能的,因为在已知宇宙的有生之年,没有足够的免费无偿志愿者秒)吗?
因为..。这不管用。
发布于 2022-03-30 05:43:42
提供狮身人面像向导@mzjn作为机敏的评论
狮身人面像不会失败地导入
typing
或其他标准模块。所有的警告都是关于丢失交叉参照目标的。为了获得对标准模块的交叉引用,使用intersphinx
.
我愚蠢地以为标准模块的交叉参照是内置的.因为这绝对应该是。不幸的是,这样做需要配置又一次正交扩张。很自然,狮身人面像不能在其警告输出中暗示这可能是个好主意--斯芬克斯甚至不会发出警告输出,除非您将秘密的-n
选项显式地传递给sphinx-build
。</double_facepalm>
谢谢公吨,@mzjn。你太棒了你知道的。
https://stackoverflow.com/questions/71626179
复制相似问题