orchestrata_ast.serialize
Reference › orchestrata_ast › serialize
serialize turns a dataclass tree from models into plain dictionaries for JSON output, using dataclasses.asdict. Anything that is not a dataclass instance, including dataclass types, passes through unchanged. It is used by analyzer and by the serializer scripts.
At a glance
| Source | src/orchestrata_ast/serialize.py |
| Lines of code | 16 |
| Classes | 0 |
| Functions | 1 |
| Imports (internal) | none |
| Imported by | orchestrata_ast, orchestrata_ast.analyzer, scripts.ast_live_sync, scripts.serialize_codebase_ast |
| Tests that import it | tests/test_orchestrata_ast_argv_literals.py, tests/test_orchestrata_ast_derive_subtree.py, tests/test_orchestrata_ast_env_access.py |
Class diagram
No classes; see Functions.
Dependency diagram
API
Functions
| Function | Signature | Summary |
|---|---|---|
serialize |
serialize(obj: object) -> object |
Convert a dataclass tree to a dict for JSON serialization. |
Source
"""Dataclass-tree -> dict serialization for the code AST — stdlib-only."""
from __future__ import annotations
from dataclasses import asdict, is_dataclass
def serialize(obj: object) -> object:
"""Convert a dataclass tree to a dict for JSON serialization.
Non-dataclass values (and dataclass TYPES, which ``asdict`` rejects)
pass through unchanged.
"""
if is_dataclass(obj) and not isinstance(obj, type):
return asdict(obj)
return obj