def to_yaml(config: Namespace | ListConfig | DictConfig) -> str:
    """Convert configuration object to YAML string.

    This function takes a configuration object and converts it to a YAML formatted string.
    It handles different configuration object types including ``Namespace``,
    ``ListConfig``, and ``DictConfig``.

    Args:
        config: Configuration object to convert. Can be one of:
            - ``Namespace``: A namespace object from OmegaConf
            - ``ListConfig``: A list configuration from OmegaConf
            - ``DictConfig``: A dictionary configuration from OmegaConf

    Returns:
        str: Configuration as YAML formatted string

    Examples:
        >>> from omegaconf import DictConfig
        >>> config = DictConfig({"model": "padim", "dataset": {"name": "mvtecad"}})
        >>> yaml_str = to_yaml(config)
        >>> print(yaml_str)
        model: padim
        dataset:
          name: mvtec

    Note:
        - For ``Namespace`` objects, the function first converts to dictionary format
        - Nested paths in the configuration are converted to strings
        - The original configuration object is not modified
    """
    _config = config.clone() if isinstance(config, Namespace) else config.copy()
    if isinstance(_config, Namespace):
        _config = _config.as_dict()
        _config = _convert_nested_path_to_str(_config)
    return OmegaConf.to_yaml(_config)
Convert configuration object to YAML string.

    This function takes a configuration object and converts it to a YAML formatted string.
    It handles different configuration object types including ``Namespace``,
    ``ListConfig``, and ``DictConfig``.

    Args:
        config: Configuration object to convert. Can be one of:
            - ``Namespace``: A namespace object from OmegaConf
            - ``ListConfig``: A list configuration from OmegaConf
            - ``DictConfig``: A dictionary configuration from OmegaConf

    Returns:
        str: Configuration as YAML formatted string

    Examples:
        >>> from omegaconf import DictConfig
        >>> config = DictConfig({"model": "padim", "dataset": {"name": "mvtecad"}})
        >>> yaml_str = to_yaml(config)
        >>> print(yaml_str)
        model: padim
        dataset:
          name: mvtec

    Note:
        - For ``Namespace`` objects, the function first converts to dictionary format
        - Nested paths in the configuration are converted to strings
        - The original configuration object is not modified
    
src/anomalib/utils/config.py