How to document a module constant in Python?

后端 未结 8 1147
忘掉有多难
忘掉有多难 2020-12-13 11:57

I have a module, errors.py in which several global constants are defined (note: I understand that Python doesn\'t have constants, but I\'ve defined them by conv

8条回答
  •  失恋的感觉
    2020-12-13 12:42

    The Sphinx Napoleon Python documentation extension allows to document module-level variables in an Attributes section.

    Per https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html :

    Attributes
    ----------
    module_level_variable1 : int
        Module level variables may be documented in either the ``Attributes``
        section of the module docstring, or in an inline docstring immediately
        following the variable.
    
        Either form is acceptable, but the two should not be mixed. Choose
        one convention to document module level variables and be consistent
        with it.
    

提交回复
热议问题