caikit.core.signature_parsing.docstrings

This package handles all the gorp of finding types from docstrings given our custom conventions

Attributes

log

Functions

get_return_type(→ Optional[Type])

Grabs the return type off the docstring, if possible

is_optional(→ bool)

Checks if the arg_name param from `fn`s docstring is optional

get_arg_type(→ Optional[Type])

Grabs the type of the arg_name param from `fn`s docstring, if possible

_get_candidate_type_names_from_docstring(...)

_get_docstring_type(→ Optional[Type])

Given a parsed docstring parameter, look in all of the possible places

_extract_nested_type(→ Optional[Type])

_extract_type_from_pymodule(→ Optional[Type])

This walks down a type hierarchy to try to find the concrete type given an input string name

Module Contents

caikit.core.signature_parsing.docstrings.log[source]
caikit.core.signature_parsing.docstrings.get_return_type(fn: Callable) Type | None[source]

Grabs the return type off the docstring, if possible Args:

fn: The function to get the return value of

e.g. my_caikit_library.modules.classification.Transformer.run

Returns:

The return type of fn, if it can be parsed from the docstring. Otherwise, None

caikit.core.signature_parsing.docstrings.is_optional(fn: Callable, arg_name: str) bool[source]

Checks if the arg_name param from `fn`s docstring is optional by checking if param description starts with “an optional” or “optional”.

Args:
fn: The function to get the type of a parameter from

e.g. my_caikit_library.modules.classification.Transformer.run

arg_name: The name of the parameter that we should try to get the type of

e.g. “raw_document”

caikit.core.signature_parsing.docstrings.get_arg_type(fn: Callable, arg_name: str) Type | None[source]

Grabs the type of the arg_name param from `fn`s docstring, if possible Args:

fn: The function to get the type of a parameter from

e.g. my_caikit_library.modules.classification.Transformer.run

arg_name: The name of the parameter that we should try to get the type of

e.g. “raw_document”

Returns:

The return type of fn, if it can be parsed from the docstring. Otherwise, None

caikit.core.signature_parsing.docstrings._get_candidate_type_names_from_docstring(param: docstring_parser.common.DocstringParam | None) Tuple[List[str], List[str]][source]
caikit.core.signature_parsing.docstrings._get_docstring_type(candidate_type_names: List[str]) Type | None[source]

Given a parsed docstring parameter, look in all of the possible places for the actual type

caikit.core.signature_parsing.docstrings._extract_nested_type(type_name: str) Type | None[source]
caikit.core.signature_parsing.docstrings._extract_type_from_pymodule(py_module: Type | Dict, type_name: str) Type | None[source]

This walks down a type hierarchy to try to find the concrete type given an input string name

Args:
py_module (Type | Dict): A python module, or dictionary of modules, to

start walking to find “type_name”

type_name (str): The name of the type that we’re trying to find. e.g.

“caikit.core.data_model.ProducerId”

Returns:

Optional[Type]: The type of “type_name”, or None if it cannot be found