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