ml_switcheroo.core.rewriter.normalization_utils¶
Normalization Utilities.
This module provides helper functions for converting between Python runtime values and LibCST Abstract Syntax Tree nodes. It supports primitive types (int, float, bool, str) and recursive container types (list, tuple, dict).
Functions¶
|
Extracts a string representation of a primitive AST node for Enum key lookup. |
|
Recursively converts a python value (primitive/container) to a CST literal expression node. |
Module Contents¶
- ml_switcheroo.core.rewriter.normalization_utils.extract_primitive_key(node: libcst.BaseExpression) str | None[source]¶
Extracts a string representation of a primitive AST node for Enum key lookup.
Handles simple strings strings, integers, and simple names (identifiers).
- Parameters:
node – The CST expression node.
- Returns:
The string value (if literal) or variable name. Returns None if the node type is complex or unsupported.
- ml_switcheroo.core.rewriter.normalization_utils.convert_value_to_cst(val: Any) libcst.BaseExpression[source]¶
Recursively converts a python value (primitive/container) to a CST literal expression node.
Supported types: - Primitives: bool, int, float, str, None - Containers: list, tuple, dict
- Parameters:
val – The python value to convert.
- Returns:
The corresponding LibCST node.