Skip to content

Manifest_Argument

Manifest_Argument

CodeEngineManifest_Argument dataclass

CodeEngineManifest_Argument(
    annotation_text: str,
    has_default_value: bool = None,
    ast_arg: arg = None,
    schema_type: PythonTypeToSchemaType = None,
    is_list: bool = False,
    is_nullable: bool = False,
    name: str = None,
    default_value: str = None,
    display_name: str = None,
    value: str = None,
    children: list[Any] = list(),
)

Bases: CodeEngine_Argument

display class for formatting AST Argument

CodeEngine_Argument dataclass

CodeEngine_Argument(
    annotation_text: str,
    has_default_value: bool = None,
    ast_arg: arg = None,
    schema_type: PythonTypeToSchemaType = None,
    is_list: bool = False,
    is_nullable: bool = False,
)

converts Python type annotations to Domo CodeEngine argument schema types.

extract_inner_list

extract_inner_list() -> str

Extract the inner element type from list[InnerType] annotations.

Parses list type annotations to determine the type of elements contained within the list, supporting both typing.list and built-in list formats.

Parameters:

Name Type Description Default
annotation_text str

list type annotation (e.g., 'list[str]', 'list[int]')

required

Returns:

Name Type Description
str str

The inner type without the list wrapper (e.g., 'str', 'int')

Examples:

'list[str]' -> 'str' 'list[int]' -> 'int' 'list[dict[str, Any]]' -> 'dict[str, Any]'

Source code in src/crew_dcs/classes/DomoCodeEngine/Manifest_Argument.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def extract_inner_list(self) -> str:
    """
    Extract the inner element type from list[InnerType] annotations.

    Parses list type annotations to determine the type of elements contained
    within the list, supporting both typing.list and built-in list formats.

    Args:
        annotation_text (str): list type annotation (e.g., 'list[str]', 'list[int]')

    Returns:
        str: The inner type without the list wrapper (e.g., 'str', 'int')

    Examples:
        'list[str]' -> 'str'
        'list[int]' -> 'int'
        'list[dict[str, Any]]' -> 'dict[str, Any]'
    """

    # is this superfluoous given how enum has been implemented with "in" checks?

    self.is_list = False
    if "list[" in self.annotation_text:
        self.is_list = True
        return self.is_list
    if "list[" in self.annotation_text:
        self.is_list = True

    return self.is_list

test_is_list_type

test_is_list_type() -> bool

Check if the type annotation represents a list or array type.

Detects various list type patterns including typing.list, built-in list, and generic list annotations from both Python 3.8+ and earlier versions.

Examples:

'list[str]' -> True 'list[int]' -> True 'list' -> True 'str' -> False

Source code in src/crew_dcs/classes/DomoCodeEngine/Manifest_Argument.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def test_is_list_type(self) -> bool:
    """
    Check if the type annotation represents a list or array type.

    Detects various list type patterns including typing.list, built-in list,
    and generic list annotations from both Python 3.8+ and earlier versions.

    Examples:
        'list[str]' -> True
        'list[int]' -> True
        'list' -> True
        'str' -> False
    """

    self.is_list = (
        "list[" in self.annotation_text
        or "list[" in self.annotation_text
        or self.annotation_text.lower() == "list"
    )

test_is_nullable

test_is_nullable() -> str

tests for Optional[] or Union[Type, None] wrappers from type annotation strings.

Examples:

'str | None' -> 'str' 'Union[int, None]' -> 'int' 'Union[None, str]' -> 'str'

Source code in src/crew_dcs/classes/DomoCodeEngine/Manifest_Argument.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def test_is_nullable(self) -> str:
    """
    tests for Optional[] or Union[Type, None] wrappers from type annotation strings.

    Examples:
        'str | None' -> 'str'
        'Union[int, None]' -> 'int'
        'Union[None, str]' -> 'str'
    """

    self.is_nullable = False  # assumes no default value

    if "Optional[" in self.annotation_text or (
        "Union[" in self.annotation_text and "None" in self.annotation_text
    ):
        self.is_nullable = True

    elif isinstance(self.has_default_value, bool):
        self.is_nullable = self.has_default_value

    return self.is_nullable

extract_ast_arg_default_value

extract_ast_arg_default_value(
    arg, ast_fn: FunctionDef
) -> dict[str, bool]

Extract the default value for a function parameter if it exists.

Note

Handles different AST node types (Constant, Name) and uses ast.unparse() when available for complex expressions.

Source code in src/crew_dcs/classes/DomoCodeEngine/Manifest_Argument.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def extract_ast_arg_default_value(arg, ast_fn: ast.FunctionDef) -> dict[str, bool]:
    """
    Extract the default value for a function parameter if it exists.

    Note:
        Handles different AST node types (Constant, Name) and uses ast.unparse()
        when available for complex expressions.
    """

    args = ast_fn.args.args
    defaults = ast_fn.args.defaults
    num_defaults = len(defaults)

    if num_defaults == 0:
        return {"default_value": None, "has_default_value": False}

    # Map default values to the last N arguments
    for darg, default in zip(args[-num_defaults:], defaults):  # noqa: B905
        if darg == arg:
            if isinstance(default, ast.Constant):
                return {"default_value": default.value, "has_default_value": True}
            if isinstance(default, ast.Name):
                return {"default_value": default.id, "has_default_value": True}
            if hasattr(ast, "unparse"):
                return {
                    "default_value": ast.unparse(default),
                    "has_default_value": True,
                }
            return {"default_value": "None", "has_default_value": True}

    return {"default_value": None, "has_default_value": False}

extract_ast_arg_type_annotation

extract_ast_arg_type_annotation(ast_arg: arg) -> str

Extract type annotation from a function parameter AST node.

Converts AST type annotation nodes back to string representation, handling different Python versions and annotation formats. Falls back to manual parsing for older Python versions without ast.unparse().

Note

Uses ast.unparse() when available (Python 3.9+), otherwise attempts manual extraction for common annotation types like ast.Name and ast.Subscript.

Source code in src/crew_dcs/classes/DomoCodeEngine/Manifest_Argument.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def extract_ast_arg_type_annotation(
    ast_arg: ast.arg,
) -> str:  # String representation of the type annotation, empty if none exists
    """
    Extract type annotation from a function parameter AST node.

    Converts AST type annotation nodes back to string representation,
    handling different Python versions and annotation formats. Falls back
    to manual parsing for older Python versions without ast.unparse().

    Note:
        Uses ast.unparse() when available (Python 3.9+), otherwise attempts
        manual extraction for common annotation types like ast.Name and ast.Subscript.
    """

    if not getattr(ast_arg, "annotation", None):
        return ""

    if hasattr(ast, "unparse"):
        return ast.unparse(ast_arg.annotation)

    if isinstance(ast_arg.annotation, ast.Name):
        return ast_arg.annotation.id
    if isinstance(ast_arg.annotation, ast.Subscript):
        return str(ast_arg.annotation)

    return ""