reproduce_cell02_constructor.py

"""Read source AST only; never import cloud/application modules or execute them."""
import ast
import inspect
from pathlib import Path

root = Path(__file__).resolve().parents[4]
tree = ast.parse((root / "src/core/srpvdal.py").read_text())
cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "SRPVDAL")
init = next(n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == "__init__")
names = [arg.arg for arg in init.args.args]
assert names == ["self", "config", "kg_client"], names
assert init.args.kwarg is None
signature = inspect.Signature([
    inspect.Parameter(name, inspect.Parameter.POSITIONAL_OR_KEYWORD,
                      default=None if name != "self" else inspect.Parameter.empty)
    for name in names
])
provider = ast.parse((root / "src/cells/cell02/srpvdal_api.py").read_text())
function = next(n for n in provider.body if isinstance(n, ast.FunctionDef)
                and n.name == "get_srpvdal_orchestrator")
call = next(n for n in ast.walk(function) if isinstance(n, ast.Call)
            and isinstance(n.func, ast.Name) and n.func.id == "SRPVDAL")
keywords = {kw.arg: None for kw in call.keywords}
print("Constructor:", signature)
print("Provider keywords:", sorted(keywords))
try:
    signature.bind(object(), **keywords)
except TypeError as error:
    print("Reproduced source mismatch:", repr(error))
else:
    raise AssertionError("Mismatch no longer reproduces; remeasure the current implementation")
← All docsView source on GitHub →