ml_switcheroo.core.escape_hatch¶
Escape Hatch Mechanism for Untranslatable Code.
This module provides the EscapeHatch class, responsible for wrapping code that cannot be deterministically transpiled with specific marker comments. It ensures that broken or partial translations are not emitted silently.
Reliability Logic:
START_MARKER: injected into the leading lines of the failed statement.
END_MARKER: injected via a sentinel statement (Ellipsis) following the failure.
Verbatim Preservation: The caller is responsible for passing the original node to avoid emitting partially mutated (broken) code.
Classes¶
Handles the "Pass-Through" Protocol. |
Module Contents¶
- class ml_switcheroo.core.escape_hatch.EscapeHatch¶
Handles the “Pass-Through” Protocol. Wraps untranslatable nodes with standardized comment flags and valid Python syntax markers.
- START_MARKER = '# <SWITCHEROO_FAILED_TO_TRANS>'¶
- END_MARKER = '# </SWITCHEROO_FAILED_TO_TRANS>'¶
- static mark_failure(node: libcst.CSTNode, reason: str) libcst.CSTNode | libcst.FlattenSentinel¶
Attaches warning comments to the node and appends an end marker.
- Transformation:
original_stmt()
- Becomes:
# <SWITCHEROO_FAILED_TO_TRANS> # Reason: … original_stmt() # </SWITCHEROO_FAILED_TO_TRANS> …
- Parameters:
node – The CST node (typically original_node) to preserve.
reason – Human-readable explanation of the failure.
- Returns:
A FlattenSentinel containing the preserved node (with header) and a footer node (Ellipsis) containing the end marker.