readthedocs / sphinx-autoapi

A new approach to API documentation in Sphinx.
https://sphinx-autoapi.readthedocs.io/
MIT License
415 stars 126 forks source link

How to display an argument as optional #378

Closed liebsc21 closed 1 year ago

liebsc21 commented 1 year ago

I am using autodoc_typehints = "description" in conf.py to add type hints in the rendered docstring. Then the following docstring

def func(param1: int, param2: int = 0):
    """...
    Args:
      param1: description1
      param2: description2
    """

is rendered like this:

param1 (int): description1
param2 (int): description2

So far so good. But next I would like my rendered docstring to display whether a parameter is optional, i.e. has a default. In other words I want it to look like this:

param1 (int): description1
param2 (int, optional): description2

Is there a way to achieve this automatically?

AWhetter commented 1 year ago

This currently isn't possible. The inclusion of types in the docstring is handled by the sphinx.ext.autodoc.typehints extension. So if you wanted this behaviour then you should request it in Sphinx.