gpt4 book ai didi

python-sphinx - Google 样式文档字符串示例部分未呈现为代码片段

转载 作者:行者123 更新时间:2023-12-03 14:18:45 25 4
gpt4 key购买 nike

我最近开始向我的项目添加文档,并且我正在尝试遵循 Google 风格指南。我正在使用 Sphinx 生成文档,并使用 Sphinx 扩展拿破仑来弥合 Google 样式指南和 reST 之间的差距。

我在渲染参数和注释时没有问题,但我似乎无法让示例部分渲染代码片段。

class Chicken(object):
"""Animal that lays egg and has feathers

Note:
Chickens love to eat feed

Example:
chicken.eats(feed)
"""

我还尝试在示例部分使用双冒号。
Example::

最佳答案

Example:: 之间需要一个双冒号和一个空行分节符和文字块。

查看示例 from the Napoleon docs :

"""Example Google style docstrings.

This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.

Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including
literal blocks::

$ python example_google.py

Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.
"""

所以,在你的例子中,试试这个:
class Chicken(object):
"""Animal that lays egg and has feathers

Note:
Chickens love to eat feed

Example::

chicken.eats(feed)
"""

关于python-sphinx - Google 样式文档字符串示例部分未呈现为代码片段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44577360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com