ml_switcheroo.utils.node_diff ============================= .. py:module:: ml_switcheroo.utils.node_diff .. autoapi-nested-parse:: AST Node Serialization for Visual Diffs. This utility module provides mechanisms to convert arbitrary LibCST nodes textual source code representation "in vacuum". This is essential for capturing states of the AST before and after transformations without requiring full file serialization. Functions --------- .. autoapisummary:: ml_switcheroo.utils.node_diff.capture_node_source ml_switcheroo.utils.node_diff.diff_nodes Module Contents --------------- .. py:function:: capture_node_source(node: libcst.CSTNode) -> str Renders a LibCST node into its Python source code string representation. This handles both original nodes (which might carry whitespace info) and constructed nodes (detached from the original tree). :param node: The CST node to serialise. :returns: The Python code string. :rtype: str .. py:function:: diff_nodes(original: libcst.CSTNode, modified: libcst.CSTNode) -> tuple[str, str, bool] Compares two nodes and returns their source strings if they differ. :param original: The node before transformation. :param modified: The node after transformation. :returns: (source_before, source_after, has_changed) :rtype: tuple