Skip to main content

DocFunctionOverload

ClassDataClassSource

DocFunctionOverload(
descr: str,
args: list[DocArgument] = [],
retval: list[DocArgument] = [],
is_yield: bool = False
)

The docstring and basic information of a function overload.

This data type will override the default argument and result rendering of a function if it exists.

Fields​

NameTypeRequired
Description
descrstrThe description body of the function.
argslist[DocArgument]The list of input arguments of the function.
retvallist[DocArgument]The list of returned values of the function.
is_yieldboolA flag. If it is True, the function returns an iterator.

Methods​

as_md_text​

v_1: str = self.as_md_text(
renderer: ProtocolComponent,
has_descr: bool = True,
ignore_self: bool = False,
title: str = "Arguments",
title_level: int = 3,
)

Render as Markdown text.

This overload rendering will only contains the information specified in the overload data model.

Requires​

NameTypeRequired
Description
rendererProtocolComponentThe renderer providing component rendering.
has_descrboolA flag. If specified, will add the overload description to the results.
ignore_selfboolA flag. If specified, will ignore the first argument (self or cls) in the argument list. Needs to be specified when the function is a method/classmethod of a class. In this case, the first argument will be skipped.
titlestrThe title of the overload information.
title_levelintThe level of the title when displaying this overload.

Returns​

NameType
Description
v_1strThe Markdown text rendered from the overload of the function.

format_args​

v_1: tuple[str, ...] = self.format_args(parent: DocFunction, ignore_self: bool = False)

Format argument list in the name: type = default style.

This method is modified from inspect.Signature.format().

Requires​

NameTypeRequired
Description
parentDocFunctionThe parent data model containing the shared information.
ignore_selfboolA flag. If specified, will remove self and cls arguments in methods.

Returns​

NameType
Description
v_1tuple[str, ...]A list of formatted arguments.

str_v1​

v_1: str = self.str_v1(parent: DocFunction)

Format the function signature as a string.

The string format is compatible with the black formatter.

Requires​

NameTypeRequired
Description
parentDocFunctionThe parent data model containing the shared information.

Returns​

NameType
Description
v_1strThe formatted signature of the overload.

str_v2​

v_1: str = self.str_v2(parent: DocFunction)

Render as V2 string.

The v2 string is in the following format:

ret: type = name(arg1: type1, arg2: type2 = default2, ...)

which is more compact than the default string.

Requires​

NameTypeRequired
Description
parentDocFunctionThe parent data model containing the shared information.

Returns​

NameType
Description
v_1strThe formatted signature of the overload.

table_args​

v_1: str = self.table_args(
renderer: ProtocolComponent,
ignore_self: bool = False,
has_type: bool = True,
has_required: bool = True,
has_default: bool = False,
has_doc: bool = True,
)

Format the arguments as a table.

Requires​

NameTypeRequired
Description
rendererProtocolComponentThe renderer providing component rendering.
ignore_selfboolA flag. Needs to be specified when the function is a method/classmethod of a class. In this case, the first argument will be skipped.
has_typeboolA flag. If specified, will display the argument type.
has_requiredboolA flag. If specified, will display whether the argument is required.
has_defaultboolA flag. If specified, will display the default value of the argument.
has_docboolA flag. If specified, will display the docstring of the argument.

Returns​

NameType
Description
v_1strThe Markdown table of the arguments.

table_retval​

v_1: str = self.table_retval(
is_renamed: bool = True, has_type: bool = True, has_doc: bool = True
)

Format the returned values as a table.

Requires​

NameTypeRequired
Description
is_renamedboolA flag. If specified, will automatically rename the numbered returned value in the v2 format.
has_typeboolA flag. If specified, will display the argument type.
has_docboolA flag. If specified, will display the docstring of the argument.

Returns​

NameType
Description
v_1strThe Markdown table of the arguments.