Is it possible to hide Python function arguments in Sphinx?

I agree that it's probably a symptom of poor design -- but I've just run into a case where I had to insert a useless **kwargs argument just to satisfy the mypy static type checker...

So, building on the suggestion by mzjn, I've published a simple sphix extension to hide arguments from the documentation:

https://pypi.org/project/sphinxcontrib-autodoc-filterparams/


It is possible to edit the function signature in a handler for the autodoc-process-signature event.

The signature parameter of the event handler holds the signature; a string of the form (parameter_1, parameter_2). In the snippet below, split() is used to remove the last parameter of a function:

hidden = "_hidden_argument"

def process_sig(app, what, name, obj, options, signature, return_annotation):
    if signature and hidden in signature:
        signature = signature.split(hidden)[0] + ")" 
    return (signature, return_annotation)

def setup(app):
    app.connect("autodoc-process-signature", process_sig)

The result is that the documentation will show the signature of the function in the question as foo(x, y) instead of foo(x, y, _hidden_argument=None).


I don't think there is an option for that in Sphinx. One possible way to accomplish this without having to hack into the code, is to use customized signature.

In this case, you need something like:

.. autofunction:: some_module.foo(x, y)

This will override the parameter list of the function and hide the unwanted argument in the doc.