injector_spec¶

LibCST Transformer for Injecting Specifications.

This tool modifies Python source files (specifically standards_internal.py) by locating the INTERNAL_OPS dictionary and appending a new operation definition derived from an ODL (Operation Definition Language) model.

Update: Now supports persisting semantic constraints (min, max, options) into the dictionary structure.

Classes¶

StandardsInjector

Injects a new operation definition into the INTERNAL_OPS dict.

Module Contents¶

class injector_spec.StandardsInjector(op_def: ml_switcheroo.core.dsl.OperationDef)¶

Bases: libcst.CSTTransformer

Injects a new operation definition into the INTERNAL_OPS dict.

It transforms the abstract OperationDef into a concrete LibCST Dictionary node structure, including rich parameter metadata (min, max, options) and appends it to the existing dictionary in the source.

op_def¶

The operation model to inject.

Type:

OperationDef

found¶

Flag indicating if the injection target (INTERNAL_OPS) was found.

Type:

bool

op_def¶
found = False¶
leave_Assign(original_node: libcst.Assign, updated_node: libcst.Assign) → libcst.Assign¶

Visits assignment statements to find INTERNAL_OPS.

If found, modifies the dictionary value to include the new key-value pair.

Parameters:
  • original_node – The node before transformation.

  • updated_node – The node after transformation (containing any recursive changes).

Returns:

The modified assignment node.

Return type:

cst.Assign