# Path: omegaconf/errors.py
# class ConfigIndexError(OmegaConfBaseException, IndexError):
#     """
#     Thrown from a config object when a regular access would have caused an IndexError.
#     """
# 
# class ConfigTypeError(OmegaConfBaseException, TypeError):
#     """
#     Thrown from a config object when a regular access would have caused a TypeError.
#     """
# 
# class ConfigValueError(OmegaConfBaseException, ValueError):
#     """
#     Thrown from a config object when a regular access would have caused a ValueError.
#     """
# 
# class GrammarParseError(OmegaConfBaseException):
#     """
#     Thrown when failing to parse an expression according to the ANTLR grammar.
#     """
# 
# class OmegaConfBaseException(Exception):
#     # would ideally be typed Optional[Node]
#     parent_node: Any
#     child_node: Any
#     key: Any
#     full_key: Optional[str]
#     value: Any
#     msg: Optional[str]
#     cause: Optional[Exception]
#     object_type: Optional[Type[Any]]
#     object_type_str: Optional[str]
#     ref_type: Optional[Type[Any]]
#     ref_type_str: Optional[str]
# 
#     _initialized: bool = False
# 
#     def __init__(self, *_args: Any, **_kwargs: Any) -> None:
#         self.parent_node = None
#         self.child_node = None
#         self.key = None
#         self.full_key = None
#         self.value = None
#         self.msg = None
#         self.object_type = None
#         self.ref_type = None
# 
# class ValidationError(OmegaConfBaseException, ValueError):
#     """
#     Thrown when a value fails validation
#     """
# 
# Path: omegaconf/grammar_parser.py
# SIMPLE_INTERPOLATION_PATTERN = re.compile(
#     f"({_outer})?({_inter}({_outer})?)+$", flags=re.ASCII
# )
# 
# def parse(
#     value: str, parser_rule: str = "configValue", lexer_mode: str = "DEFAULT_MODE"
# ) -> ParserRuleContext:
#     """
#     Parse interpolated string `value` (and return the parse tree).
#     """
#     l_mode = getattr(OmegaConfGrammarLexer, lexer_mode)
#     istream = InputStream(value)
# 
#     cached = getattr(_grammar_cache, "data", None)
#     if cached is None:
#         error_listener = OmegaConfErrorListener()
#         lexer = OmegaConfGrammarLexer(istream)
#         lexer.removeErrorListeners()
#         lexer.addErrorListener(error_listener)
#         lexer.mode(l_mode)
#         token_stream = CommonTokenStream(lexer)
#         parser = OmegaConfGrammarParser(token_stream)
#         parser.removeErrorListeners()
#         parser.addErrorListener(error_listener)
# 
#         # The two lines below could be enabled in the future if we decide to switch
#         # to SLL prediction mode. Warning though, it has not been fully tested yet!
#         # from antlr4 import PredictionMode
#         # parser._interp.predictionMode = PredictionMode.SLL
# 
#         # Note that although the input stream `istream` is implicitly cached within
#         # the lexer, it will be replaced by a new input next time the lexer is re-used.
#         _grammar_cache.data = lexer, token_stream, parser
# 
#     else:
#         lexer, token_stream, parser = cached
#         # Replace the old input stream with the new one.
#         lexer.inputStream = istream
#         # Initialize the lexer / token stream / parser to process the new input.
#         lexer.mode(l_mode)
#         token_stream.setTokenSource(lexer)
#         parser.reset()
# 
#     try:
#         return getattr(parser, parser_rule)()
#     except Exception as exc:
#         if type(exc) is Exception and str(exc) == "Empty Stack":
#             # This exception is raised by antlr when trying to pop a mode while
#             # no mode has been pushed. We convert it into an `GrammarParseError`
#             # to facilitate exception handling from the caller.
#             raise GrammarParseError("Empty Stack")
#         else:
#             raise


import copy
import os
import re
import string
import sys
import warnings
import yaml
    import dataclasses
    import attr
    import typing  # lgtm [py/import-and-import-from]
from contextlib import contextmanager
from enum import Enum
from textwrap import dedent
from typing import (
    Any,
    Dict,
    Iterator,
    List,
    Optional,
    Tuple,
    Type,
    Union,
    get_type_hints,
)
from .errors import (
    ConfigIndexError,
    ConfigTypeError,
    ConfigValueError,
    GrammarParseError,
    OmegaConfBaseException,
    ValidationError,
)
from .grammar_parser import SIMPLE_INTERPOLATION_PATTERN, parse
    from importlib import import_module
    from .base import Container, Node
    from omegaconf.omegaconf import _maybe_wrap
    from omegaconf.omegaconf import OmegaConf, _maybe_wrap
    from omegaconf import MISSING
    from omegaconf.omegaconf import MISSING, OmegaConf, _maybe_wrap
    from omegaconf.base import Node
    from omegaconf.base import Node
    from omegaconf import Node
    from omegaconf import Node
    from .base import Container
    from omegaconf import DictKeyType
    from .base import Container
    from .nodes import ValueNode
    from omegaconf import Container, Node
    from omegaconf import OmegaConf
    from omegaconf.base import Node
    from omegaconf import OmegaConf

    d = {}
    is_type = isinstance(obj, type)
    obj_type = obj if is_type else type(obj)
    dummy_parent = OmegaConf.create({}, flags=flags)
    dummy_parent._metadata.object_type = obj_type

    for name, attrib in attr.fields_dict(obj_type).items():
        is_optional, type_ = _resolve_optional(attrib.type)
        type_ = _resolve_forward(type_, obj.__module__)
        if not is_type:
            value = getattr(obj, name)
        else:
            value = attrib.default
            if value == attr.NOTHING:
                value = MISSING
        if _is_union(type_):
            e = ConfigValueError(
                f"Union types are not supported:\n{name}: {type_str(type_)}"
            )
            format_and_raise(node=None, key=None, value=value, cause=e, msg=str(e))

        try:
            d[name] = _maybe_wrap(
                ref_type=type_,
                is_optional=is_optional,
                key=name,
                value=value,
                parent=dummy_parent,
            )

# Path: omegaconf/errors.py
# class ConfigIndexError(OmegaConfBaseException, IndexError):
#     """
#     Thrown from a config object when a regular access would have caused an IndexError.
#     """
# 
# class ConfigTypeError(OmegaConfBaseException, TypeError):
#     """
#     Thrown from a config object when a regular access would have caused a TypeError.
#     """
# 
# class ConfigValueError(OmegaConfBaseException, ValueError):
#     """
#     Thrown from a config object when a regular access would have caused a ValueError.
#     """
# 
# class GrammarParseError(OmegaConfBaseException):
#     """
#     Thrown when failing to parse an expression according to the ANTLR grammar.
#     """
# 
# class OmegaConfBaseException(Exception):
#     # would ideally be typed Optional[Node]
#     parent_node: Any
#     child_node: Any
#     key: Any
#     full_key: Optional[str]
#     value: Any
#     msg: Optional[str]
#     cause: Optional[Exception]
#     object_type: Optional[Type[Any]]
#     object_type_str: Optional[str]
#     ref_type: Optional[Type[Any]]
#     ref_type_str: Optional[str]
# 
#     _initialized: bool = False
# 
#     def __init__(self, *_args: Any, **_kwargs: Any) -> None:
#         self.parent_node = None
#         self.child_node = None
#         self.key = None
#         self.full_key = None
#         self.value = None
#         self.msg = None
#         self.object_type = None
#         self.ref_type = None
# 
# class ValidationError(OmegaConfBaseException, ValueError):
#     """
#     Thrown when a value fails validation
#     """
# 
# Path: omegaconf/grammar_parser.py
# SIMPLE_INTERPOLATION_PATTERN = re.compile(
#     f"({_outer})?({_inter}({_outer})?)+$", flags=re.ASCII
# )
# 
# def parse(
#     value: str, parser_rule: str = "configValue", lexer_mode: str = "DEFAULT_MODE"
# ) -> ParserRuleContext:
#     """
#     Parse interpolated string `value` (and return the parse tree).
#     """
#     l_mode = getattr(OmegaConfGrammarLexer, lexer_mode)
#     istream = InputStream(value)
# 
#     cached = getattr(_grammar_cache, "data", None)
#     if cached is None:
#         error_listener = OmegaConfErrorListener()
#         lexer = OmegaConfGrammarLexer(istream)
#         lexer.removeErrorListeners()
#         lexer.addErrorListener(error_listener)
#         lexer.mode(l_mode)
#         token_stream = CommonTokenStream(lexer)
#         parser = OmegaConfGrammarParser(token_stream)
#         parser.removeErrorListeners()
#         parser.addErrorListener(error_listener)
# 
#         # The two lines below could be enabled in the future if we decide to switch
#         # to SLL prediction mode. Warning though, it has not been fully tested yet!
#         # from antlr4 import PredictionMode
#         # parser._interp.predictionMode = PredictionMode.SLL
# 
#         # Note that although the input stream `istream` is implicitly cached within
#         # the lexer, it will be replaced by a new input next time the lexer is re-used.
#         _grammar_cache.data = lexer, token_stream, parser
# 
#     else:
#         lexer, token_stream, parser = cached
#         # Replace the old input stream with the new one.
#         lexer.inputStream = istream
#         # Initialize the lexer / token stream / parser to process the new input.
#         lexer.mode(l_mode)
#         token_stream.setTokenSource(lexer)
#         parser.reset()
# 
#     try:
#         return getattr(parser, parser_rule)()
#     except Exception as exc:
#         if type(exc) is Exception and str(exc) == "Empty Stack":
#             # This exception is raised by antlr when trying to pop a mode while
#             # no mode has been pushed. We convert it into an `GrammarParseError`
#             # to facilitate exception handling from the caller.
#             raise GrammarParseError("Empty Stack")
#         else:
#             raise


# Path: omegaconf/_utils.py
import copy
import os
import re
import string
import sys
import warnings
import yaml
    import dataclasses
    import attr
    import typing  # lgtm [py/import-and-import-from]
from contextlib import contextmanager
from enum import Enum
from textwrap import dedent
from typing import (
    Any,
    Dict,
    Iterator,
    List,
    Optional,
    Tuple,
    Type,
    Union,
    get_type_hints,
)
from .errors import (
    ConfigIndexError,
    ConfigTypeError,
    ConfigValueError,
    GrammarParseError,
    OmegaConfBaseException,
    ValidationError,
)
from .grammar_parser import SIMPLE_INTERPOLATION_PATTERN, parse
    from importlib import import_module
    from .base import Container, Node
    from omegaconf.omegaconf import _maybe_wrap
    from omegaconf.omegaconf import OmegaConf, _maybe_wrap
    from omegaconf import MISSING
    from omegaconf.omegaconf import MISSING, OmegaConf, _maybe_wrap
    from omegaconf.base import Node
    from omegaconf.base import Node
    from omegaconf import Node
    from omegaconf import Node
    from .base import Container
    from omegaconf import DictKeyType
    from .base import Container
    from .nodes import ValueNode
    from omegaconf import Container, Node
    from omegaconf import OmegaConf
    from omegaconf.base import Node
    from omegaconf import OmegaConf


    d = {}
    is_type = isinstance(obj, type)
    obj_type = obj if is_type else type(obj)
    dummy_parent = OmegaConf.create({}, flags=flags)
    dummy_parent._metadata.object_type = obj_type

    for name, attrib in attr.fields_dict(obj_type).items():
        is_optional, type_ = _resolve_optional(attrib.type)
        type_ = _resolve_forward(type_, obj.__module__)
        if not is_type:
            value = getattr(obj, name)
        else:
            value = attrib.default
            if value == attr.NOTHING:
                value = MISSING
        if _is_union(type_):
            e = ConfigValueError(
                f"Union types are not supported:\n{name}: {type_str(type_)}"
            )
            format_and_raise(node=None, key=None, value=value, cause=e, msg=str(e))

        try:
            d[name] = _maybe_wrap(
                ref_type=type_,
                is_optional=is_optional,
                key=name,
                value=value,
                parent=dummy_parent,
            )

        except (ValidationError, GrammarParseError) as ex: