0

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

CaffeinatedMike
  • 1,537
  • 2
  • 25
  • 57
  • @mzjn So, only username, password, section, context_filter, report_folders, run_fixed_reports_only show up in the list of parameters with descriptions under `Child` for you? I'm also seeing log_file, secret, local_directory, folder_path, dataset, table, and columns. Please see my edit with the screenshot. – CaffeinatedMike Aug 12 '21 at 12:32
  • Yes, but I was only trying to provide a minimal example. I didn't think providing docstrings in the example would be relevant since parameters are still documented when they do not have docstrings – CaffeinatedMike Aug 12 '21 at 12:57
  • You're right, my apologies. I've updated `Parent` to include the docstring from the screenshot. – CaffeinatedMike Aug 12 '21 at 13:08

1 Answers1

0

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
CaffeinatedMike
  • 1,537
  • 2
  • 25
  • 57