How to document a module constant in Python?

后端 未结 8 1141
忘掉有多难
忘掉有多难 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:46

    the following worked for me with Sphinx 2.4.4:

    in foo.py :

    API_ERROR = 1
    """int: Indicates some unknown error."""
    
    

    then to document it:

    .. automodule:: foo.py 
        :members:
    
    
    0 讨论(0)
  • 2020-12-13 12:51

    This is an older question, but I noted that a relevant answer was missing.

    Or you can just include a description of the constants in the docstring of the module via .. py:data::. That way the documentation is also made available via the interactive help. Sphinx will render this nicely.

    """
    Docstring for my module.
    
    .. data:: API_ERROR
    
        Indicates some unknown error.
    
    .. data:: BAD_REQUEST
    
        Indicates that the request was bad in some way.
    
    .. data:: MISSING_PARAMS
    
        Indicates that the request is missing required parameters.
    """
    
    0 讨论(0)
提交回复
热议问题