Omit (or format) the value of a variable when documenting with Sphinx

后端 未结 1 1823
不思量自难忘°
不思量自难忘° 2021-01-04 07:51

I\'m currently documenting a whole module with autodoc. However, I define several variables on the module level that contain long lists or dicts. They are included in the do

相关标签:
1条回答
  • 2021-01-04 08:05

    There is no simple configuration setting for omitting values of module level variables in the output. But you can do it by modifying the DataDocumenter.add_directive_header() method in autodoc.py. The crucial line in that method is

    self.add_line(u'   :annotation: = ' + objrepr, '<autodoc>')
    

    where objrepr is the value.

    The following monkey patch added to conf.py works for me:

    from sphinx.ext.autodoc import ModuleLevelDocumenter, DataDocumenter
    
    def add_directive_header(self, sig):
        ModuleLevelDocumenter.add_directive_header(self, sig)
        # Rest of original method ignored
    
    DataDocumenter.add_directive_header = add_directive_header
    
    0 讨论(0)
提交回复
热议问题