DocDataClass
类数据类源码
DocDataClass(
name: str,
descr: str,
init_func: DocFunction = _default_init(),
init_func_specified: bool = True,
methods: list[DocFunction] = [],
properties: list[DocProp] = [],
operators: list[DocOpTemplate] = [],
abstract_attrs: DocClassAbstractAttrs | None = None,
slang: str = "",
lineno: int = 0,
type: Literal["dataclass"] = "dataclass",
fields: list[DocField] = []
)
数据类/模型的 docstring 和其他基本信息。
该数据类型可序列化。包含了从数据类/模型中解析 docstring 得到的结果。它可以视为一个特殊处理后的类文档。渲染成文档时,其初始化方法相关的内容会替换成字段的详情。
字段
| 字段 | 类型 | 必选 | |
|---|---|---|---|
name | str | 类的名称。 | |
descr | str | 类的描述文字。 | |
init_func | DocFunction | 类的初始化方法。 | |
init_func_specified | bool | 布尔标记。如果该值被设置,则表明该类有着由用户定义的初始化方法。 | |
methods | list[DocFunction] | 类的所有方法列表。 | |
properties | list[DocProp] | 类的所有属性列表。 | |
operators | list[DocOpTemplate] | 类的所有运算符列表。 | |
abstract_attrs | DocClassAbstractAttrs | None | 额外的抽象成员。只在该类为抽象类的情形下存在。对于协议类型,该值将永远为None。 | |
slang | str | 该类的内部识别码。 | |
lineno | int | 定义了该类的代码所在的行号。如果该行号无法确认,则设为0。 | |
type | Literal["dataclass"] | 作为文档成员的类型标识符。 | |
fields | list[DocField] | 作为数据类/模型的数据字段列表。 |
方法
as_md_text
v_1: str = self.as_md_text(renderer: ProtocolComponent)
渲染为 Markdown 文字。
输入
| 参数 | 类型 | 必选 | |
|---|---|---|---|
renderer | ProtocolComponent | 用来渲染组件的渲染器。 |
输出
| 参数 | 类型 | |
|---|---|---|
v_1 | str | 从数据类渲染的 Markdown 文本。 |
table_fields
v_1: str = self.table_fields(
renderer: ProtocolComponent,
has_type: bool = True,
has_required: bool = True,
has_default: bool = False,
has_doc: bool = True,
)
将字段格式化为表格。
输入
| 参数 | 类型 | 必选 | |
|---|---|---|---|
renderer | ProtocolComponent | 用来渲染组件的渲染器。 | |
has_type | bool | 布尔标记。如果设置了,就会显示字段类型。 | |
has_required | bool | 布尔标记。如果设置了,就会显示字段是否为必选。 | |
has_default | bool | 布尔标记。如果设置了,就会显示字段的默认值类型。 | |
has_doc | bool | 布尔标记。如果设置了,就会显示字段的 docstring 文本。 |
输出
| 参数 | 类型 | |
|---|---|---|
v_1 | str | 包含了各字段详情的 Markdown 表格。 |
属性
str_v2
str_v2: str = self.str_v2
渲染 V2 字符串。
所谓 v2 字符串可以描述为以下格式:
ClassName(field1: type1, field2: type2 = default2, ...)
相比默认的字符串格式更加紧凑。