Skip to main content

DocDataClass

ClassDataClassSource

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] = []
)

The docstring and basic information of a data model/class.

This serializable data type contains the parsed docstrings of the data class/model. It is a specialized class. When rendering the documentation, the initialization function is replaced by the field details.

Fields​

NameTypeRequired
Description
namestrThe name of the class.
descrstrThe description body of the class.
init_funcDocFunctionThe initialization function of the class.
init_func_specifiedboolA flag. When it is on, it means that the initialization function has been defined by user.
methodslist[DocFunction]The list of methods of this class.
propertieslist[DocProp]The list of properties of this class.
operatorslist[DocOpTemplate]The list of operators of this class.
abstract_attrsDocClassAbstractAttrs | NoneAdditional abstract attributes. Will present only when the class is abstract. For the protocols, this value will be always None.
slangstrThe internal code identifying this class.
linenointThe line number where the class is defined. If the number is unknown, this value will be 0.
typeLiteral["dataclass"]The identifier of this documentation item.
fieldslist[DocField]The data fields of the data class/model.

Methods​

as_md_text​

v_1: str = self.as_md_text(renderer: ProtocolComponent)

Render as Markdown text.

Requires​

NameTypeRequired
Description
rendererProtocolComponentThe renderer providing component rendering.

Returns​

NameType
Description
v_1strThe Markdown text rendered from the data class.

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,
)

Format the fields as a table.

Requires​

NameTypeRequired
Description
rendererProtocolComponentThe renderer providing component rendering.
has_typeboolA flag. If specified, will display the field type.
has_requiredboolA flag. If specified, will display whether the field is required.
has_defaultboolA flag. If specified, will display the default value of the field.
has_docboolA flag. If specified, will display the docstring of the field.

Returns​

NameType
Description
v_1strThe Markdown table of the fields.

Properties​

str_v2​

str_v2: str = self.str_v2

Render as V2 string.

The v2 string is in the following format:

ClassName(field1: type1, field2: type2 = default2, ...)

which is more compact than the default string.