What is the correct way to document a **kwargs parameter?

后端 未结 8 1245
清酒与你
清酒与你 2021-01-30 02:48

I\'m using sphinx and the autodoc plugin to generate API documentation for my Python modules. Whilst I can see how to nicely document specific parameters, I cannot find an exam

8条回答
  •  天命终不由人
    2021-01-30 03:19

    If anyone else is looking for some valid syntax.. Here's an example docstring. This is just how I did it, I hope it's useful to you, but I can't claim that it's compliant with anything in particular.

    def bar(x=True, y=False):
        """
        Just some silly bar function.
    
        :Parameters:
          - `x` (`bool`) - dummy description for x
          - `y` (`string`) - dummy description for y
        :return: (`string`) concatenation of x and y.
        """
        return str(x) + y
    
    def foo (a, b, **kwargs):
        """
        Do foo on a, b and some other objects.
    
        :Parameters:
          - `a` (`int`) - A number.
          - `b` (`int`, `string`) - Another number, or maybe a string.
          - `\**kwargs` - remaining keyword arguments are passed to `bar`
    
        :return: Success
        :rtype: `bool`
        """
        return len(str(a) + str(b) + bar(**kwargs)) > 20
    

提交回复
热议问题