Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
pgorecki committed Apr 2, 2024
1 parent 18c2afa commit 4c5f0ec
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions lato/dependency_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,40 +109,6 @@ def _get_type_and_value(self, value):
return value.a_type, value.value
return type(value), value

def _resolve_arguments(
self, function_parameters: OrderedDict, overrides: dict[str, Any]
) -> dict[str, Any]:
"""
Resolves given function parameters to their corresponding dependencies.
:param function_parameters: Parameters of the function
:param overrides: Manual overrides for dependencies
:return: A dictionary of resolved dependencies
"""

def _resolve(identifier, overrides):
if identifier in overrides:
return overrides[identifier]
return self.get_dependency(identifier)

kwargs = {}
for param_name, param_type in function_parameters.items():
# first, try to resolve by type
if param_type == inspect.Parameter.empty:
try:
kwargs[param_name] = _resolve(param_type, overrides)
continue
except (ValueError, KeyError):
pass
# then, try to resolve by name
try:
kwargs[param_name] = _resolve(param_name, overrides)
continue
except (ValueError, KeyError):
pass

return kwargs

def resolve_func_params(
self,
func: Callable,
Expand All @@ -169,17 +135,21 @@ def resolve_func_params(
arg_idx = 0
for param_name, param_type in func_parameters.items():
if arg_idx < len(func_args):
# use positional argument given explicitly in func_args
resolved_kwargs[param_name] = func_args[arg_idx]
arg_idx += 1
continue

if param_name in func_kwargs:
# use keyword argument given explicitly in func_kwargs
resolved_kwargs[param_name] = func_kwargs[param_name]
elif param_type != inspect.Parameter.empty and self.has_dependency(
param_type
):
# resolve as dependency by type
resolved_kwargs[param_name] = self.get_dependency(param_type)
elif self.has_dependency(param_name):
# resolve as dependency by name
resolved_kwargs[param_name] = self.get_dependency(param_name)

return resolved_kwargs
Expand Down

0 comments on commit 4c5f0ec

Please sign in to comment.