Skip to content

parser ¤

PythonParser An interface to extract different parts of the provided python code into a simple metadata object.

Classes:

Name Description
PythonParser

A unified interface for accessing python parsed data.

PythonParser ¤

PythonParser(decorated: Any)

A unified interface for accessing python parsed data.

Attributes:

Name Type Description
has_any_return_defs bool

A return definition is any of the following:

has_structured_return_type bool

Except for the following types, a dedicated output parsing

Source code in src/declarai/python_parser/parser.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(self, decorated: Any):
    self.is_func = inspect.isfunction(decorated)
    self.is_class = inspect.isclass(decorated)
    self.decorated = decorated

    # Static attributes:
    self.name = self.decorated.__name__

    self._signature = inspect.signature(self.decorated)
    self.signature_return_type = self.signature_return.type_

    docstring = inspect.getdoc(self.decorated)
    self._parsed_docstring = ReSTDocstringParser(docstring or "")
    self.docstring_freeform = self._parsed_docstring.freeform
    self.docstring_params = self._parsed_docstring.params
    self.docstring_return = self._parsed_docstring.returns

has_any_return_defs cached property ¤

has_any_return_defs: bool

A return definition is any of the following: - return type annotation - return reference in docstring - return referenced in magic placeholder # TODO: Address magic reference as well.

has_structured_return_type cached property ¤

has_structured_return_type: bool

Except for the following types, a dedicated output parsing behavior is required to return the expected return type of the task.