Skip to content

Commit

Permalink
Common: Change parameters to DiContainer._resolve_default()
Browse files Browse the repository at this point in the history
  • Loading branch information
mssalvatore committed Mar 7, 2023
1 parent 2c75d17 commit cb20874
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions monkey/common/di_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def resolve_dependencies(self, type_: Type[T]) -> Sequence[Any]:
continue

with suppress(UnresolvableDependencyError):
args.append(self._resolve_default(parameter))
args.append(self._resolve_default(parameter.name, parameter.default))
continue

raise UnresolvableDependencyError(
Expand Down Expand Up @@ -194,13 +194,11 @@ def _construct_new_instance(self, arg_type: Type[T]) -> T:
def _retrieve_registered_instance(self, arg_type: Type[T]) -> T:
return self._instance_registry[arg_type]

def _resolve_default(self, parameter: inspect.Parameter) -> Any:
if parameter.default is not inspect.Parameter.empty:
return parameter.default
def _resolve_default(self, name: str, default: T) -> T:
if default is not inspect.Parameter.empty:
return default

raise UnresolvableDependencyError(
f'No default found for "{parameter.name}:{DIContainer._format_type_name(type)}"'
)
raise UnresolvableDependencyError(f'No default found for "{name}"')

def release(self, interface: Type[T]):
"""
Expand Down

0 comments on commit cb20874

Please sign in to comment.