pycharm 修改了vscode中的sphinx样式文档字符串

bwitn5fc  于 2023-01-26  发布在  PyCharm
关注(0)|答案(2)|浏览(158)

总之,我在VSCode和Pycharm中都尝试了这个。本质上我想修改我自动生成的文档字符串的样式。在VSCode中,我使用扩展名-“Python文档字符串生成器”。目前将其设置为sphinx会生成如下内容:

def test(a, b):
    """
    :param a: 
    :type a:
    :param b:
    :type b:
    :return:
    :rtype:
    """

我希望发生的是:

def test(a, b):
    """
    :param type a: 
    :param type b:
    :return:
    :rtype:
    """

有人能帮我在Pycharm或VSCode中实现这个吗?

juud5qan

juud5qan1#

看起来你可以从文档中指定一个自定义模板

The extension uses the mustache.js templating engine. To use a custom template create a .mustache file and specify its path using the customTemplatePath configuration. View the included google docstring template for a usage example. The following tags are available for use in custom templates.
Variables

{{name}}                        - name of the function
{{summaryPlaceholder}}          - [summary] placeholder
{{extendedSummaryPlaceholder}}  - [extended_summary] placeholder

Sections

{{#args}}                       - iterate over function arguments
    {{var}}                     - variable name
    {{typePlaceholder}}         - [type] or guessed type  placeholder
    {{descriptionPlaceholder}}  - [description] placeholder
{{/args}}
wh6knrhe

wh6knrhe2#

你好,谢谢你的awnser!我有一个额外的问题。我已经设法生成自己的模板如下:

{{summaryPlaceholder}}

{{#parametersExist}}

### Arguments
{{#args}}
{{var}}: `{{typePlaceholder}}`
     {{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
{{var}}: `{{typePlaceholder}}` `default = {{&default}}`
    {{descriptionPlaceholder}}
{{/kwargs}}
{{/parametersExist}}
{{#returnsExist}}

### Returns
{{#returns}}
{{return}}: `{{typePlaceholder}}`
    {{descriptionPlaceholder}}
{{/returns}}
{{/returnsExist}}

它输出以下文本:

def moving_median(list: list, window: int):
    """
    _summary_

    ### Arguments
    list: `list`
         _description_
    window: `int`
         _description_

    ### Returns
    : `_type_`
        _description_
    """

我想补充两点:

  • 每个参数和返回值前的迭代数字
  • 返回变量的名称,稍后在函数中定义。

输出应如下所示:

def moving_median(list: list, window: int):
    """
    _summary_

    ### Arguments
    1. list: `list`
         _description_
    2. window: `int`
         _description_

    ### Returns
    1. result: `_type_`
        _description_
    """

能做到吗?
先谢了

相关问题