Can Sphinx napoleon document function returning multiple arguments? Can Sphinx napoleon document function returning multiple arguments? python python

Can Sphinx napoleon document function returning multiple arguments?


Python only returns a single object. If you call

serv,msg = foo(myinput)

Then you are explicitly expanding the expression_list tuple which is generated when the function returns with this code

return servers,msg

You docstring should read some thing like this (with the Napoleon Google Style)

"""one line summarylonger explanationArgs:    a (int): parameter descriptionReturns:    (tuple): tuple containing:        servers(list) servers to use        msg (str): logging message string """

Or with the Napoleon NumPy style:

"""one line summarylonger explanationParameters----------a : int    parameter descriptionReturns-------servers : list    servers to usemsg : str    logging message string """

Have a look at the python docs for return and perhaps expression_list


Google style does not support multiple return values. As a workaround you can use:

Returns:    2-element tuple containing    - **rates** (*array*): the unnormalized rates (just the sum of the      exponential kernels). To obtain rates in Hz divide the      array by `2*tau` (or other conventional `x*tau` duration).    - **nph** (*array*): number of photons in -5*tau..5*tau window      for each timestamp. Proportional to the rate computed      with KDE and rectangular kernel.

This results in a nice output even with multi-line description for each returned item.


You can configure napoleon to interpret the Returns section of a Google-style docstring like the Args section using the napoleon_custom_sections setting.

napoleon_custom_sections = [('Returns', 'params_style')]

This way, multiple return values (as given in the question) are rendered nicely by Sphinx. However, I am not entirely sure if one is still strictly adhering to the Google-style docstring convention when using this option.