terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
483 stars 41 forks source link

Multiple returns #175

Open kmvanh opened 3 years ago

kmvanh commented 3 years ago

When a function features multiple Returns/Yields they cannot be individually mentioned in the docstring like Parameters would (see code example below).

def multiple_returns(a, b):
  """Multiple returns example.

  Parameters
  ----------
  a : int
      First integer
  b : int
      Second integer

  Returns
  -------
  diff : int
      b subtracted from a
  summation : int
      b added to a
  """
  diff = a - b
  summation = a + b
  return diff, summation

Instead darglint raises an error DAR000: Unexpected exception in darglint: Multiple types should be combined into a Union. The error message indicates that the Returns docstring should be structured something like:

  Returns
  -------
  Union[int, int]
    Tuple containing:
      diff : int
          b subtracted from a
      summation : int
          b added to a
  """

I don't think this is the neatest solution. Eventhough the return is a tuple, I would expect to be able to write a docstring for each individual returned variable. Can this functionality, like in the first example, be added (as an option) to darglint?

terrencepreilly commented 3 years ago

Sure, since it's part of the Numpy docstring spec. I haven't had time to update the numpy parser, but you're welcome to issue a pull request and I'll review it.