python - Sphinx 文档 - 如何隐藏从父类函数继承的函数参数?
问题描述
我有以下课程
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
当我尝试为Child
下面的类呈现 sphinx 文档时,我最终得到的所有Parent
类的参数仍然显示在__init__
.
.. autoclass:: Child
.. automethod:: __init__
Parent
除了手动写出每个参数之外,是否有一种简单的方法可以从参数列表中省略' Child
s 参数?
解决方案
现在我只是觉得很傻。原来我所要做的就是在其文档字符串中明确指定Child
's__init__
参数,如下所示:
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
推荐阅读
- sql - 将实际行作为参数传递给函数(ORACLE)
- ionic-framework - 当离子项目具有焦点时,离子更改标签字体大小
- pandas - Pandas 操作数据帧和异常处理
- amazon-web-services - Move contents of versioned S3 bucket with CLI
- spring-boot - 未导入gradle传递依赖项
- javascript - 将 OpenTok Publisher 切换到特定的视频设备
- r - 如何使用ggplot2中的频率表绘制条形图
- vb.net - 单击按钮时冻结程序
- apache-spark - 库存分析工具设计的设计理念
- epplus - EPPlus 图表不显示轴标签