Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def decorator(klass: T, direct_call: bool = False) -> T:
steps_back = 3 if direct_call else 2
caller_filepath = get_caller_filepath(steps_back)
if caller_filepath == InjectionContainer.LOADING_FILEPATH:
InjectionContainer._register_injectable(
klass, caller_filepath, qualifier, primary, namespace, group, singleton
)
return klass
def decorator(fn: Callable[..., T]) -> Callable[..., T]:
caller_filepath = get_caller_filepath()
if caller_filepath == InjectionContainer.LOADING_FILEPATH:
InjectionContainer._register_factory(
fn,
caller_filepath,
dependency,
qualifier,
primary,
namespace,
group,
singleton,
)
return fn
This method will be removed from the public API in the future. Use
:func:`load_injection_container` instead.
"""
warnings.warn(
"Using 'load' directly from the 'InjectionContainer' is deprecated."
" Use 'load_injection_container' instead. This class will be removed from"
" the injectable's public API in the future.",
DeprecationWarning,
2,
)
cls.LOADING_DEFAULT_NAMESPACE = default_namespace or DEFAULT_NAMESPACE
cls.NAMESPACES[default_namespace] = Namespace()
if search_path is None:
search_path = os.path.dirname(get_caller_filepath())
elif not os.path.isabs(search_path):
caller_path = os.path.dirname(get_caller_filepath())
search_path = os.path.normpath(os.path.join(caller_path, search_path))
cls._link_dependencies(search_path)
cls.LOADING_DEFAULT_NAMESPACE = None