You can specify types of parameters in Python docstrings like this:
def __init__(self, canvas, segments):
"""Class constructor.
:param canvas: the PDF canvas object
:param segment: The layer segments to be drawn.
:type canvas: `canvas.Canvas`
:type segments: list of str
"""
...
With Sphinx' autodoc feature, this yields the parameters list, and each parameter is properly tagged with their types.
But how do I do this with instance attributes? Something like this
class Path(object):
"""
:ivar edge_indices: The indices within `textured_points` of the places.
:type edge_indices: list of int
"""
does not work. One can put a single-word type after the :ivar
but here, it consists of three words, so that would not work.
Yes, you can do that! You can actually 'document' lambdas and variables in a module by attaching docstrings to them.
Let us know the most commonly used docstring formats out there in the wild, which are namely- Google, NumPy, and Sphinx docstring formats.
Declaring Docstrings: The docstrings are declared using ”'triple single quotes”' or “””triple double quotes””” just below the class, method or function declaration. All functions should have a docstring.
I had this same issue. The answer is vartype
:
class Foo:
"""
:ivar edge_indices: description
:vartype edge_indices: list of int
"""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With