class ValueKind(Enum):
    VALUE = 0
    MANDATORY_MISSING = 1
    INTERPOLATION = 2 def _is_interpolation(v: Any, strict_interpolation_validation: bool = False) -> bool:
    if isinstance(v, str):
        ret = (
            get_value_kind(v, strict_interpolation_validation)
            == ValueKind.INTERPOLATION
        )
        assert isinstance(ret, bool)
        return ret
    return False def get_type_of(class_or_object: Any) -> Type[Any]:
    type_ = class_or_object
    if not isinstance(type_, type):
        type_ = type(class_or_object)
    assert isinstance(type_, type)
    return type_ def get_value_kind(
    value: Any, strict_interpolation_validation: bool = False
) -> ValueKind:
    """
    Determine the kind of a value
    Examples:
    VALUE: "10", "20", True
    MANDATORY_MISSING: "???"
    INTERPOLATION: "${foo.bar}", "${foo.${bar}}", "${foo:bar}", "[${foo}, ${bar}]",
                   "ftp://${host}/path", "${foo:${bar}, [true], {'baz': ${baz}}}"

    :param value: Input to classify.
    :param strict_interpolation_validation: If `True`, then when `value` is a string
        containing "${", it is parsed to validate the interpolation syntax. If `False`,
        this parsing step is skipped: this is more efficient, but will not detect errors.
    """

    if _is_missing_value(value):
        return ValueKind.MANDATORY_MISSING

    value = _get_value(value)

    # We identify potential interpolations by the presence of "${" in the string.
    # Note that escaped interpolations (ex: "esc: \${bar}") are identified as
    # interpolations: this is intended, since they must be processed as interpolations
    # for the string to be properly un-escaped.
    # Keep in mind that invalid interpolations will only be detected when
    # `strict_interpolation_validation` is True.
    if isinstance(value, str) and "${" in value:
        if strict_interpolation_validation:
            # First try the cheap regex matching that detects common interpolations.
            if SIMPLE_INTERPOLATION_PATTERN.match(value) is None:
                # If no match, do the more expensive grammar parsing to detect errors.
                parse(value)
        return ValueKind.INTERPOLATION
    else:
        return ValueKind.VALUE def is_primitive_container(obj: Any) -> bool:
    return is_primitive_list(obj) or is_primitive_dict(obj) def type_str(t: Any, include_module_name: bool = False) -> str:
    is_optional, t = _resolve_optional(t)
    if t is None:
        return type(t).__name__
    if t is Any:
        return "Any"
    if t is ...:
        return "..."

    if sys.version_info < (3, 7, 0):  # pragma: no cover
        # Python 3.6
        if hasattr(t, "__name__"):
            name = str(t.__name__)
        else:
            if t.__origin__ is not None:
                name = type_str(t.__origin__)
            else:
                name = str(t)
                if name.startswith("typing."):
                    name = name[len("typing.") :]
    else:  # pragma: no cover
        # Python >= 3.7
        if hasattr(t, "__name__"):
            name = str(t.__name__)
        else:
            if t._name is None:
                if t.__origin__ is not None:
                    name = type_str(
                        t.__origin__, include_module_name=include_module_name
                    )
            else:
                name = str(t._name)

    args = getattr(t, "__args__", None)
    if args is not None:
        args = ", ".join(
            [type_str(t, include_module_name=include_module_name) for t in t.__args__]
        )
        ret = f"{name}[{args}]"
    else:
        ret = name
    if include_module_name:
        if (
            hasattr(t, "__module__")
            and t.__module__ != "builtins"
            and t.__module__ != "typing"
            and not t.__module__.startswith("omegaconf.")
        ):
            module_prefix = t.__module__ + "."
        else:
            module_prefix = ""
        ret = module_prefix + ret
    if is_optional:
        return f"Optional[{ret}]"
    else:
        return ret class Metadata:
class ContainerMetadata(Metadata):
class Node(ABC):
class Container(Node):
class SCMode(Enum):
    def __post_init__(self) -> None:
    def __post_init__(self) -> None:
    def __init__(self, parent: Optional["Container"], metadata: Metadata):
    def __getstate__(self) -> Dict[str, Any]:
    def __setstate__(self, state_dict: Dict[str, Any]) -> None:
    def _set_parent(self, parent: Optional["Container"]) -> None:
    def _invalidate_flags_cache(self) -> None:
    def _get_parent(self) -> Optional["Container"]:
    def _set_flag(
        self,
        flags: Union[List[str], str],
        values: Union[List[Optional[bool]], Optional[bool]],
    ) -> "Node":
    def _get_node_flag(self, flag: str) -> Optional[bool]:
    def _get_flag(self, flag: str) -> Optional[bool]:
    def _get_flag_no_cache(self, flag: str) -> Optional[bool]:
    def _format_and_raise(
        self,
        key: Any,
        value: Any,
        cause: Exception,
        msg: Optional[str] = None,
        type_override: Any = None,
    ) -> None:
    def _get_full_key(self, key: Optional[Union[DictKeyType, int]]) -> str:
    def _dereference_node(self) -> "Node":
    def _maybe_dereference_node(
        self,
        throw_on_resolution_failure: bool = False,
        memo: Optional[Set[int]] = None,
    ) -> Optional["Node"]:
    def _dereference_node_impl(
        self,
        throw_on_resolution_failure: bool,
        memo: Optional[Set[int]] = None,
    ) -> Optional["Node"]:
    def _get_root(self) -> "Container":
    def _is_missing(self) -> bool:
    def _is_none(self) -> bool:
    def __eq__(self, other: Any) -> bool:
    def __ne__(self, other: Any) -> bool:
    def __hash__(self) -> int:
    def _value(self) -> Any:
    def _set_value(self, value: Any, flags: Optional[Dict[str, bool]] = None) -> None:
    def _is_optional(self) -> bool:
    def _is_interpolation(self) -> bool:
    def _key(self) -> Any:
    def _set_key(self, key: Any) -> None:
    def _is_flags_root(self) -> bool:
    def _set_flags_root(self, flags_root: bool) -> None:
    def _get_node(
        self,
        key: Any,
        validate_access: bool = True,
        validate_key: bool = True,
        throw_on_missing_value: bool = False,
        throw_on_missing_key: bool = False,
    ) -> Union[Optional[Node], List[Optional[Node]]]:
    def __delitem__(self, key: Any) -> None:
    def __setitem__(self, key: Any, value: Any) -> None:
    def __iter__(self) -> Iterator[Any]:
    def __getitem__(self, key_or_index: Any) -> Any:
    def __copy__(self) -> Any:
    def _resolve_key_and_root(self, key: str) -> Tuple["Container", str]:
    def _select_impl(
        self,
        key: str,
        throw_on_missing: bool,
        throw_on_resolution_failure: bool,
        memo: Optional[Set[int]] = None,
    ) -> Tuple[Optional["Container"], Optional[str], Optional[Node]]:
    def _resolve_interpolation_from_parse_tree(
        self,
        parent: Optional["Container"],
        value: "Node",
        key: Any,
        parse_tree: OmegaConfGrammarParser.ConfigValueContext,
        throw_on_resolution_failure: bool,
        memo: Optional[Set[int]],
    ) -> Optional["Node"]:
    def _validate_and_convert_interpolation_result(
        self,
        parent: Optional["Container"],
        value: "Node",
        key: Any,
        resolved: Any,
        throw_on_resolution_failure: bool,
    ) -> Optional["Node"]:
    def _validate_not_dereferencing_to_parent(self, node: Node, target: Node) -> None:
    def _resolve_node_interpolation(
        self, inter_key: str, memo: Optional[Set[int]]
    ) -> "Node":
    def _evaluate_custom_resolver(
        self,
        key: Any,
        node: Node,
        inter_type: str,
        inter_args: Tuple[Any, ...],
        inter_args_str: Tuple[str, ...],
    ) -> Any:
    def _maybe_resolve_interpolation(
        self,
        parent: Optional["Container"],
        key: Any,
        value: Node,
        throw_on_resolution_failure: bool,
        memo: Optional[Set[int]] = None,
    ) -> Optional[Node]:
    def resolve_parse_tree(
        self,
        parse_tree: ParserRuleContext,
        node: Node,
        memo: Optional[Set[int]] = None,
        key: Optional[Any] = None,
        parent: Optional["Container"] = None,
    ) -> Any:
        def node_interpolation_callback(
            inter_key: str, memo: Optional[Set[int]]
        ) -> Optional["Node"]:
        def resolver_interpolation_callback(
            name: str, args: Tuple[Any, ...], args_str: Tuple[str, ...]
        ) -> Any:
    def _re_parent(self) -> None:
    def _invalidate_flags_cache(self) -> None:
    def _has_ref_type(self) -> bool:
    DICT = 1  # Convert to plain dict
    DICT_CONFIG = 2  # Keep as OmegaConf DictConfig
    INSTANTIATE = 3  # Create a dataclass or attrs class instance class ReadonlyConfigError(OmegaConfBaseException):
    """
    Thrown when someone tries to modify a frozen config
    """ class UnsupportedValueType(ValidationError, ValueError):
    """
    Thrown when an input value is not of supported type
    """ class ValidationError(OmegaConfBaseException, ValueError):
    """
    Thrown when a value fails validation
    """
import copy
import math
import sys
from abc import abstractmethod
from enum import Enum
from typing import Any, Dict, Optional, Type, Union
from omegaconf._utils import (
    ValueKind,
    _is_interpolation,
    get_type_of,
    get_value_kind,
    is_primitive_container,
    type_str,
)
from omegaconf.base import Container, DictKeyType, Metadata, Node
from omegaconf.errors import ReadonlyConfigError, UnsupportedValueType, ValidationError
        from omegaconf import read_write
        from ._utils import is_primitive_type
        from omegaconf import OmegaConf



class ValueNode(Node):
    _val: Any

    def __init__(self, parent: Optional[Container], value: Any, metadata: Metadata):

        super().__init__(parent=parent, metadata=metadata)
        with read_write(self):
            self._set_value(value)  # lgtm [py/init-calls-subclass]

    def _value(self) -> Any:
        return self._val

    def _set_value(self, value: Any, flags: Optional[Dict[str, bool]] = None) -> None:
        if self._get_flag("readonly"):
            raise ReadonlyConfigError("Cannot set value of read-only config node")


        if isinstance(value, str) and get_value_kind(