Search code examples
pythondocumentationpython-sphinxautodoc

Sphinx documentation - How can I hide function parameters inherited from the parent class' function?


I have the following classes

import abc


class Parent(metaclass=abc.ABCMeta):
    def __init__(
        self,
        username: str,
        password: str,
        log_file: Optional[str] = None,
        secret: Optional[str] = None,
        local_directory: Optional[str] = None,
        folder_path: Optional[str] = None,
        dataset: Optional[str] = None,
        table: Optional[str] = None,
        columns: Optional[list] = None
    ) -> None:
        """
        :param username: The username or email address of the account used to login to the portal.
        :param password: The password of the account used to login to the portal.
        :param log_file: The log file that all log statements will be stored in. Defaults to stdout.
        :param secret: The secret used to generate valid codes for the account.
        :param local_directory: The working directory where files are saved during runtime.
        :param folder_path: The folder that the reports will be stored in.
        :param dataset: The dataset that will be used to upload the report data to.
        :param table: The table inside ``dataset`` that will house the report data.
        :param columns: The columns as seen in either the downloaded files (recommended) or ``table``.
        """
        pass



class Child(Parent):
    def __init__(
        self,
        username: str,
        password: str,
        section: str,
        context_filter: str = None,
        report_folders: list = None,
        run_fixed_reports_only: bool = False,
        **kwargs
    ) -> None:
        pass

When I try to render sphinx documentation for the Child class like below, I end up with all of the Parent class' parameters still showing up under the __init__.

.. autoclass:: Child

   .. automethod:: __init__

Is there a simple way to omit Parent's parameters from the list of parameters other than manually writing out each of Child's parameters?

Edit: To include a screenshot of the end result I'm receiving that shows the inherited fields being shown under the list of parameters before Child's parameters. enter image description here


Solution

  • Now I just feel silly. Turns out all I had to do was explicitly specify Child's __init__ parameters in its docstring like so:

    class Child(Parent):
        def __init__(
            self,
            username: str,
            password: str,
            portal: str,
            context_filter: str = None,
            report_folders: list = None,
            run_fixed_reports_only: bool = False,
            **kwargs
        ) -> None:
            """
            :param username:
            :param password:
            :param portal:
            :param context_filter:
            :param report_folders:
            :param run_fixed_reports_only:
            :param kwargs: Parameters to pass to the parent class :class:`Parent`.
            """
            pass