Source code for annotatedyaml.objects

"""Custom yaml object types."""

from __future__ import annotations

from dataclasses import dataclass
from typing import Any

import voluptuous as vol
import yaml
from voluptuous.schema_builder import _compile_scalar


[docs] class NodeListClass(list): """Wrapper class to be able to add attributes on a list.""" __slots__ = ("__config_file__", "__line__") __config_file__: str __line__: int | str
[docs] class NodeStrClass(str): """Wrapper class to be able to add attributes on a string.""" __slots__ = ("__config_file__", "__line__") __config_file__: str __line__: int | str def __voluptuous_compile__(self, schema: vol.Schema) -> Any: """Needed because vol.Schema.compile does not handle str subclasses.""" return _compile_scalar(self)
[docs] class NodeDictClass(dict): """Wrapper class to be able to add attributes on a dict.""" __slots__ = ("__config_file__", "__line__") __config_file__: str __line__: int | str
[docs] @dataclass(slots=True, frozen=True) class Input: """Input that should be substituted.""" name: str
[docs] @classmethod def from_node(cls, loader: yaml.Loader, node: yaml.nodes.Node) -> Input: """Create a new placeholder from a node.""" return cls(node.value)