Skip to content

docments

docments

Docments: documentation harvested from code (inline comments, docstrings), plus flexiclass and the UNSET sentinel.

Nothing here talks to a model. functai.signature uses these helpers to turn comments into instructions and field descriptions.

Functions

Name Description
docments The documentation of a function's parameters and return, read from its comments.
docstring Get cleaned docstring for functions and classes.
extract_docstrings Return mapping {name: (docstring, paramlist)} for top-level symbols in code.
flexiclass Make a plain annotated class a dataclass, as @ai does for types.
get_dataclass_source Get source code for dataclass s.
get_source Get source code for string, function object, class, or dataclass.
isdataclass Check if s is a dataclass class (not an instance).
parse_docstring Split a numpy-style docstring into its parts.
sig2str Generate a function signature string with inline docments comments.

docments

docments.docments(
    elt,
    full=False,
    args_kwargs=False,
    returns=True,
    eval_str=False,
)

The documentation of a function's parameters and return, read from its comments.

Generate comment docs for functions or classes.

For functions: returns {param_name: comment, 'return': comment?} For classes: returns {field_name: comment} If full=True, each value becomes {'anno': ..., 'default': ..., 'docment': ...}.

docstring

docments.docstring(sym)

Get cleaned docstring for functions and classes.

extract_docstrings

docments.extract_docstrings(code)

Return mapping {name: (docstring, paramlist)} for top-level symbols in code.

flexiclass

docments.flexiclass(cls)

Make a plain annotated class a dataclass, as @ai does for types.

Convert cls to a dataclass IN PLACE, giving UNSET defaults to any annotated field that doesn't already have a default.

Usages: @flexiclass class Person: name: str; age: int; city: str = "Unknown"

# or
class Person: ...
flexiclass(Person)

Returns

Name Type Description
dataclass The same class object, mutated to be a dataclass.

get_dataclass_source

docments.get_dataclass_source(s)

Get source code for dataclass s.

get_source

docments.get_source(s)

Get source code for string, function object, class, or dataclass.

isdataclass

docments.isdataclass(s)

Check if s is a dataclass class (not an instance).

parse_docstring

docments.parse_docstring(sym)

Split a numpy-style docstring into its parts.

Parse a subset of numpy-style docstrings:

Parameters

name : type description...

Returns

type description... Returns dict with 'param:' and 'return' keys when found.

sig2str

docments.sig2str(func)

Generate a function signature string with inline docments comments.