【问题标题】:Add dictionary keys in docstring sphinx在文档字符串 sphinx 中添加字典键
【发布时间】:2019-07-30 06:30:20
【问题描述】:

为字典的键添加文档字符串的推荐方法是什么?我正在使用 python 2.7 和 Sphinx。

例如,在下面的代码中,我应该如何提及 my_dict 的键 'a' 和 'b'? (但也许没有必要详细说明):

def my_func(my_dict):
    """
    :param dict {'a': float, 'b': str} my_dict: description of param
    """
    pass

我的 Pycharm 编辑器似乎无法识别上面的实现

编辑:我也读过this post,但答案没有提到如何指定键的“名称”

【问题讨论】:

标签: python dictionary python-sphinx docstring


【解决方案1】:

我通常选择numpy style。根据我的个人经验,我相信这是 SciPy/NumPy/pandas 生态系统中常用的文档字符串样式。对于上面的函数,你可以这样写。

def my_func(my_dict):
    """
    Parameters
    ----------
    my_dict : dict
        dict of {str: int}.
    """
    pass

请参阅pandas docstring guide 以供参考。

【讨论】:

  • 问题是询问 reStructuredText 表单文档字符串,既不是 google 样式也不是 NumPy 样式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 2018-09-20
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多