neogen icon indicating copy to clipboard operation
neogen copied to clipboard

reST Python docstrings: Requesting a new option to disable types, and for Neogen to add info about exceptions

Open sseneca opened this issue 2 years ago • 0 comments

I'm using reST docstrings for Python and then generating documentation via Sphinx.

Say I have this function:

def test(a: int) -> int:
    if a == 0:
        raise Exception
    return a

Calling Neogen (configured to use reST) gives me this:

def test(a: int) -> int:
    """[TODO:description]

    :param a: [TODO:description]
    :type a: int [TODO:description]
    :return: [TODO:return]
    :rtype: [TODO:return]
    """
    if a == 0:
        raise Exception
    return a

First, since I'm already using type hints as defined in PEP 484, I use sphinx-autodoc-typehints which means I can write docstrings as follows:

def test(a: int) -> int:
    """[TODO:description]

    :param a: [TODO:description]
    :return: [TODO:return]
    """
    if a == 0:
        raise Exception
    return a

The rest is redundant; Sphinx figures out the types on its own.

Second, why doesn't it add anything about the Exception? Ideally, I'd like the autogenerated docstring to look like this:

def test(a: int) -> int:
"""[TODO:description]

:param a: [TODO:description]
:raises Exception: [TODO:description]
:return: [TODO:return]
"""
if a == 0:
    raise Exception
return a

Thanks 🙂

sseneca avatar Aug 03 '22 16:08 sseneca