Common: Rename UnregisteredTypeError to UnresolvableDependencyError

When calling `resolve()`, dependencies may be resolved as conventions,
instances, or types. `UnregisteredTypeError` is overly specific and, in
some cases, inaccurate. It makes more sense for `resolve()` to raise an
`UnresolvableDependencyError` if it is unable to resolve a dependency.
This commit is contained in:
Mike Salvatore 2022-08-05 11:37:07 -04:00
parent 34ed72da6b
commit d8b37553e3
3 changed files with 7 additions and 7 deletions

View File

@ -1,5 +1,5 @@
"""
Used for a common things between agent and island
"""
from .di_container import DIContainer, UnregisteredTypeError
from .di_container import DIContainer, UnresolvableDependencyError
from .operating_systems import OperatingSystems

View File

@ -6,7 +6,7 @@ from common.utils.code_utils import del_key
T = TypeVar("T")
class UnregisteredTypeError(ValueError):
class UnresolvableDependencyError(ValueError):
pass
@ -109,7 +109,7 @@ class DIContainer:
"""
try:
return self._resolve_type(type_)
except UnregisteredTypeError:
except UnresolvableDependencyError:
pass
args = self.resolve_dependencies(type_)
@ -153,7 +153,7 @@ class DIContainer:
elif type_ in self._instance_registry:
return self._retrieve_registered_instance(type_)
raise UnregisteredTypeError(
raise UnresolvableDependencyError(
f'Failed to resolve unregistered type "{DIContainer._format_type_name(type)}"'
)

View File

@ -1,7 +1,7 @@
from typing import Any, Sequence, Type, TypeVar
from unittest.mock import MagicMock
from common import DIContainer, UnregisteredTypeError
from common import DIContainer, UnresolvableDependencyError
T = TypeVar("T")
@ -10,11 +10,11 @@ class StubDIContainer(DIContainer):
def resolve(self, type_: Type[T]) -> T:
try:
return super().resolve(type_)
except UnregisteredTypeError:
except UnresolvableDependencyError:
return MagicMock()
def resolve_dependencies(self, type_: Type[T]) -> Sequence[Any]:
try:
return super().resolve_dependencies(type_)
except UnregisteredTypeError:
except UnresolvableDependencyError:
return MagicMock()