Documenting class attributes with type annotations Documenting class attributes with type annotations python python

Documenting class attributes with type annotations


I do not think you can put an Attribute section inside of your docstring to get your desired results.

I tried giving each attribute a doc comment and specified the type and desired comment.

class DataHolder:"""Class to hold some dataEach attribute needs its own doc comment with its type"""#: bool: Run without Guibatch = False#: bool: Show debug messagesdebug = False#: str: Object Namename = 'default'#: int: Object Versionversion = 0

This gives the following output and a nice Type description of each output.

Take a look here:

Please take a look here!


class DataHolder:    """    Class to hold some data    Attributes:        batch: Run without GUI        debug (bool): Show debug messages        name: Object name        version: Object version    """    batch: bool = False    debug: bool = False    name: str = 'default'    version: int = 0    # INLINE COMMENT for ONE line    """    DocString as inline-comment I havent seen that yet.    """


There is an inbuilt library for document generation from doc_strings.

https://docs.python.org/2/library/pydoc.html

All you need is to execute

$ pydoc <modulename>

It gives a beautiful documentation listing the doc_strings, defines the parameters and the return values.Just give a try.