Skip to main content

DocOpTemplate

ClassDataClassSource

DocOpTemplate(
name: str,
template: str,
func: DocFunction,
special: Literal["no", "yield"] = "no"
)

The template of the plain operator.

For example, the len operator can be implemented by:

DocOpTemplate(name="len", template="{vr1}: {tr1} = len({va1})")

Another example is the getitem operator which can be type-specified:

DocOpTemplate(name="getitem", template="data: DataType = value[key]")

Fields

NameTypeRequired
Description
namestrThe name of the operator (do not include the underlines).
templatestrThe template content. Use "{vr1}", "{tr1}", "{va1}", "{ta1}", ... to represent the variables and types in the returned values and arguments, respectively.
funcDocFunctionThe function body of the docstring.
specialLiteral["no", "yield"]The special case of the string version rendering. If not specified, will use the template to render the results.

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 operator.

from_func

v_1: Self = DocOpTemplate.from_func(func: Any, base_cls: type[Any])

Create the DocOpTemplate from an operator function.

Requires

NameTypeRequired
Description
funcAnyThe method function used for creating this operator template.
base_clstype[Any]The class where the operator is defined.

Returns

NameType
Description
v_1SelfThe operator template created from the given operator method.

Properties

str_v2

str_v2: str = self.str_v2

Render as V2 string.

The v2 string is in the following format:

template.format(
va1=self.func.args[0].name, a1=self.func.args[0].type,
...
vr1=self.func.retval[0].name, r1=self.func.retval[0].type,
...
)

which is more compact than the default string.