Skip to content

ConfigConstructor

Base classes

Name Children Inherits
Constructor
yaml.constructor

⋔ Inheritance diagram

graph TD
  1433436033["variable.ConfigConstructor"]
  541669724["constructor.Constructor"]
  3483163399["constructor.UnsafeConstructor"]
  2724229419["constructor.FullConstructor"]
  225296175["constructor.SafeConstructor"]
  1507651137["constructor.BaseConstructor"]
  2751680898["builtins.object"]
  541669724 --> 1433436033
  3483163399 --> 541669724
  2724229419 --> 3483163399
  225296175 --> 2724229419
  1507651137 --> 225296175
  2751680898 --> 1507651137

🛈 DocStrings

Bases: Constructor

Custom YAML constructor with variable support.

Source code in src/configz/yaml_tools/constructors/variable.py
class ConfigConstructor(Constructor):
    """Custom YAML constructor with variable support."""

    def __init__(self, variables: Mapping[str, Any] | None = None) -> None:
        super().__init__()
        self.variables: Mapping[str, Any] = variables or {}

    def construct_variable(self, loader: Any, node: Any) -> Any:
        """Construct a variable reference."""
        value = loader.construct_scalar(node)
        if not isinstance(value, str):
            msg = f"Invalid variable reference: {value}"
            raise TypeError(msg)
        return self.variables.get(value, VariableReference(value))

construct_variable

construct_variable(loader: Any, node: Any) -> Any

Construct a variable reference.

Source code in src/configz/yaml_tools/constructors/variable.py
def construct_variable(self, loader: Any, node: Any) -> Any:
    """Construct a variable reference."""
    value = loader.construct_scalar(node)
    if not isinstance(value, str):
        msg = f"Invalid variable reference: {value}"
        raise TypeError(msg)
    return self.variables.get(value, VariableReference(value))

:fa-brands-github: Show source on GitHub