forked from p15670423/monkey
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:
parent
34ed72da6b
commit
d8b37553e3
|
@ -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
|
||||
|
|
|
@ -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)}"'
|
||||
)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue