Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for kwarg in specs.kwonlyargs if is_injectable(kwarg, specs)
}
if len(injectables) is 0:
logging.warning("Function '{function}' is annotated with"
" '@autowired' but no arguments that"
" qualify as injectable were found"
.format(function=func.__name__))
else:
injectables = {
kwarg: specs.annotations.get(kwarg)
for kwarg in injectable_kwargs
}
redundant_lazy_use = False
for kwarg, ref in injectables.items():
if is_lazy(ref):
redundant_lazy_use = lazy
continue
if not isinstance(ref, str):
continue
cls = get_class(ref, func_module)
if cls is None:
continue
injectables[kwarg] = cls
if redundant_lazy_use:
logging.warning("@autowired decorator is set to always lazy"
" initialize dependencies. Usage of 'lazy'"
" function to mark dependencies as lazy is"
def get_instance(reference, func_module, force_lazy):
if isinstance(reference, str):
if force_lazy:
return Proxy(lambda: get_class(reference, func_module)())
return get_class(reference, func_module)()
if is_lazy(reference):
if isinstance(reference(), str):
r = reference()
return Proxy(lambda: get_class(r, func_module)())
return Proxy(reference())
if force_lazy:
return Proxy(reference)
return reference()
continue
injectables[kwarg] = cls
if redundant_lazy_use:
logging.warning("@autowired decorator is set to always lazy"
" initialize dependencies. Usage of 'lazy'"
" function to mark dependencies as lazy is"
" redundant")
for kwarg, cls in injectables.items():
issue = None
if kwarg not in specs.kwonlyargs:
issue = "Injectable arguments must be keyword arguments only"
if issue is None and (lazy or is_lazy(cls)):
continue
if isinstance(cls, str):
cls = get_class(cls, func_module)
if issue is None and cls is None:
issue = ("Unable to find a reference to the annotated class."
" You may want to try marking this dependency as"
" lazy: ... {argument}: lazy('YourClass') ..."
.format(argument=kwarg))
if issue is None and not inspect.isclass(cls):
issue = ("Injectable arguments must be annotated with a"
" class type")
if issue is None: