Search code examples
pythondocstring

Python Google docstring format: more than one type for argument?


I am using Google-style python docstring format. There's one function, and the input parameter could be dict, list, or string. What is the format of multiple data type in docstring?

Like

Args:
    input (str, list, dict): input of this function

Solution

  • As it is stated in the Sphinx 1.5 documentation describing this style of formatting, PEP 484 type annotations are supported.

    PEP 484 specifies the Union type as appropriate for a situation where you have a limited set of accepted types for an argument. In your example it will be:

    Args:
        input (Union[str, list, dict]): input of this function