Skip to content

Commit

Permalink
cleanup : remove _OmegaConfException
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Apr 4, 2020
1 parent 9ddbc0c commit e32805e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 52 deletions.
36 changes: 20 additions & 16 deletions omegaconf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import yaml

from .errors import KeyValidationError, ValidationError, _OmegaConfException
from .errors import KeyValidationError, ValidationError

try:
import dataclasses
Expand Down Expand Up @@ -402,27 +402,33 @@ def _get_value(value: Any) -> Any:
return value


def format_and_raise(oce: _OmegaConfException) -> None:
def format_and_raise(
node: Any,
key: Any,
value: Any,
exception_type: Any,
msg: str,
cause: Optional[Exception] = None,
) -> None:
def type_str(t: Any) -> str:
if isinstance(t, type):
return t.__name__
else:
return str(node._metadata.object_type)

key = oce.key
key = key
if key is None:
node = oce.node
node = node
else:
if oce.node is None or oce.node._is_none() or oce.node._is_missing():
if node is None or node._is_none() or node._is_missing():
node = None
else:
if isinstance(key, slice):
node = oce.node
node = node
else:
node = oce.node.get_node_ex(key, validate_access=False)
if node is None:
node = oce.node
else:
child_node = node.get_node_ex(key, validate_access=False)
if child_node is not None:
node = child_node
key = None

if node is None:
Expand All @@ -443,13 +449,13 @@ def type_str(t: Any) -> str:
else:
rt = f"Optional[{rt}]"

msg = string.Template(oce.msg).substitute(
msg = string.Template(msg).substitute(
REF_TYPE=rt,
OBJECT_TYPE=object_type,
KEY=key,
FULL_KEY=full_key,
VALUE=oce.value,
VALUE_TYPE=f"{type(oce.value).__name__}",
VALUE=value,
VALUE_TYPE=f"{type(value).__name__}",
KEY_TYPE=f"{type(key).__name__}",
)

Expand All @@ -463,6 +469,4 @@ def type_str(t: Any) -> str:
message = s.substitute(
REF_TYPE=rt, OBJECT_TYPE=object_type, MSG=msg, FULL_KEY=full_key,
)
raise oce.exception_type(f"{message}").with_traceback(
sys.exc_info()[2]
) from oce.cause
raise exception_type(f"{message}").with_traceback(sys.exc_info()[2]) from cause
16 changes: 3 additions & 13 deletions omegaconf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from typing import Any, Dict, Iterator, Optional, Tuple, Type, Union

from ._utils import ValueKind, _get_value, format_and_raise, get_value_kind
from .errors import (
MissingMandatoryValue,
UnsupportedInterpolationType,
_OmegaConfException,
)
from .errors import MissingMandatoryValue, UnsupportedInterpolationType


@dataclass
Expand Down Expand Up @@ -92,15 +88,9 @@ def _get_flag(self, flag: str) -> Optional[bool]:
def _translate_exception(
self, e: Exception, key: Any, value: Any, type_override: Any = None
) -> None:
etype = type(e) if type_override is None else type_override
format_and_raise(
_OmegaConfException(
exception_type=type(e) if type_override is None else type_override,
node=self,
key=key,
value=value,
msg=str(e),
cause=e,
)
exception_type=etype, node=self, key=key, value=value, msg=str(e), cause=e,
)
assert False # pragma: no cover

Expand Down
23 changes: 0 additions & 23 deletions omegaconf/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from typing import Any, Optional


class MissingMandatoryValue(Exception):
"""Thrown when a variable flagged with '???' value is accessed to
indicate that the value was not set"""
Expand Down Expand Up @@ -34,23 +31,3 @@ class UnsupportedInterpolationType(ValueError):
"""
Thrown when an attempt to use an unregistered interpolation is made
"""


class _OmegaConfException(Exception):
def __init__(
self,
node: Any,
key: Any,
value: Any,
exception_type: Any,
msg: str,
cause: Optional[Exception] = None,
):
super().__init__(msg)
assert exception_type != _OmegaConfException
self.node = node
self.key = key
self.value = value
self.exception_type = exception_type
self.msg = msg
self.cause = cause

0 comments on commit e32805e

Please sign in to comment.