0

There is a previous question on getting Sphinx to document certain special methods only (the __init__(self) in that case): How to use Sphinx's autodoc to document a class's __init__(self) method?

The accepted answer lists 3 options, the first of which is to use a custom function to handle the "autodoc-skip-member" event. The answer suggests adding this code to conf.py:

def skip(app, what, name, obj, skip, options):
    if name == "__init__":
        return False
    return skip

def setup(app):
    app.connect("autodoc-skip-member", skip)

This would really work great in my case, since it is global, i.e. requires no editing of *.rst files. The problem is, I cannot get it to work. I added the code to conf.py, however, the __init__() method does not show up in the docs. I can use

autodoc_default_flags = ['special-members']

to include all special methods, but I was really hoping to have more control and include just some of them (__init__() and possibly __repr__()). Does this approach work for other people? Is there anything else I need to do to get it to work?

Thanks, Aleksey

bad_coder
  • 11,289
  • 20
  • 44
  • 72
user2690051
  • 155
  • 1
  • 1
  • 9
  • 1
    Are you by any chance also using napoleon? I have a similar symptom in that scenario. http://stackoverflow.com/questions/36270358/sphinx-autodoc-skip-member-handler-cant-show-init-when-using-napoleon – Scott Mar 28 '16 at 20:21

1 Answers1

0

Per https://github.com/sphinx-doc/sphinx/issues/2374, where the conflict is with Napoleon, if you're using any extensions that also sets a handler for the "autodoc-skip-member" event only one of the handlers will be used. Could this be the issue you encountered?

Scott
  • 1,247
  • 3
  • 10
  • 21