mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-05-22 13:36:15 +03:00
Add implementation and typing stubs
This commit is contained in:
parent
bafd1843da
commit
33e80333b1
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -184,6 +184,13 @@ cdef class List(Provider):
|
||||||
cpdef object _provide(self, tuple args, dict kwargs)
|
cpdef object _provide(self, tuple args, dict kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
cdef class Dict(Provider):
|
||||||
|
cdef tuple __kwargs
|
||||||
|
cdef int __kwargs_len
|
||||||
|
|
||||||
|
cpdef object _provide(self, tuple args, dict kwargs)
|
||||||
|
|
||||||
|
|
||||||
cdef class Container(Provider):
|
cdef class Container(Provider):
|
||||||
cdef object __container_cls
|
cdef object __container_cls
|
||||||
cdef dict __overriding_providers
|
cdef dict __overriding_providers
|
||||||
|
|
|
@ -9,8 +9,8 @@ from typing import (
|
||||||
Any,
|
Any,
|
||||||
Tuple,
|
Tuple,
|
||||||
List as _List,
|
List as _List,
|
||||||
|
Dict as _Dict,
|
||||||
Optional,
|
Optional,
|
||||||
Dict,
|
|
||||||
Union,
|
Union,
|
||||||
Coroutine as _Coroutine,
|
Coroutine as _Coroutine,
|
||||||
)
|
)
|
||||||
|
@ -29,7 +29,7 @@ class OverridingContext:
|
||||||
class Provider(Generic[T]):
|
class Provider(Generic[T]):
|
||||||
def __init__(self) -> None: ...
|
def __init__(self) -> None: ...
|
||||||
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
|
def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
|
||||||
def __deepcopy__(self, memo: Optional[Dict[Any, Any]]) -> Provider: ...
|
def __deepcopy__(self, memo: Optional[_Dict[Any, Any]]) -> Provider: ...
|
||||||
def __str__(self) -> str: ...
|
def __str__(self) -> str: ...
|
||||||
def __repr__(self) -> str: ...
|
def __repr__(self) -> str: ...
|
||||||
@property
|
@property
|
||||||
|
@ -44,7 +44,7 @@ class Provider(Generic[T]):
|
||||||
def provider(self) -> Provider: ...
|
def provider(self) -> Provider: ...
|
||||||
@property
|
@property
|
||||||
def provided(self) -> ProvidedInstance: ...
|
def provided(self) -> ProvidedInstance: ...
|
||||||
def _copy_overridings(self, copied: Provider, memo: Optional[Dict[Any, Any]]) -> None: ...
|
def _copy_overridings(self, copied: Provider, memo: Optional[_Dict[Any, Any]]) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class Object(Provider, Generic[T]):
|
class Object(Provider, Generic[T]):
|
||||||
|
@ -74,7 +74,7 @@ class DependenciesContainer(Object):
|
||||||
def __init__(self, **dependencies: Provider) -> None: ...
|
def __init__(self, **dependencies: Provider) -> None: ...
|
||||||
def __getattr__(self, name: str) -> Provider: ...
|
def __getattr__(self, name: str) -> Provider: ...
|
||||||
@property
|
@property
|
||||||
def providers(self) -> Dict[str, Provider]: ...
|
def providers(self) -> _Dict[str, Provider]: ...
|
||||||
|
|
||||||
|
|
||||||
class Callable(Provider, Generic[T]):
|
class Callable(Provider, Generic[T]):
|
||||||
|
@ -88,7 +88,7 @@ class Callable(Provider, Generic[T]):
|
||||||
def set_args(self, *args: Injection) -> Callable[T]: ...
|
def set_args(self, *args: Injection) -> Callable[T]: ...
|
||||||
def clear_args(self) -> Callable[T]: ...
|
def clear_args(self) -> Callable[T]: ...
|
||||||
@property
|
@property
|
||||||
def kwargs(self) -> Dict[str, Injection]: ...
|
def kwargs(self) -> _Dict[str, Injection]: ...
|
||||||
def add_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
|
def add_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
|
||||||
def set_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
|
def set_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
|
||||||
def clear_kwargs(self) -> Callable[T]: ...
|
def clear_kwargs(self) -> Callable[T]: ...
|
||||||
|
@ -135,7 +135,7 @@ class ConfigurationOption(Provider):
|
||||||
def update(self, value: Any) -> None: ...
|
def update(self, value: Any) -> None: ...
|
||||||
def from_ini(self, filepath: Union[Path, str]) -> None: ...
|
def from_ini(self, filepath: Union[Path, str]) -> None: ...
|
||||||
def from_yaml(self, filepath: Union[Path, str]) -> None: ...
|
def from_yaml(self, filepath: Union[Path, str]) -> None: ...
|
||||||
def from_dict(self, options: Dict[str, Any]) -> None: ...
|
def from_dict(self, options: _Dict[str, Any]) -> None: ...
|
||||||
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
|
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class Configuration(Object):
|
||||||
def update(self, value: Any) -> None: ...
|
def update(self, value: Any) -> None: ...
|
||||||
def from_ini(self, filepath: Union[Path, str]) -> None: ...
|
def from_ini(self, filepath: Union[Path, str]) -> None: ...
|
||||||
def from_yaml(self, filepath: Union[Path, str]) -> None: ...
|
def from_yaml(self, filepath: Union[Path, str]) -> None: ...
|
||||||
def from_dict(self, options: Dict[str, Any]) -> None: ...
|
def from_dict(self, options: _Dict[str, Any]) -> None: ...
|
||||||
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
|
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,12 +174,12 @@ class Factory(Provider, Generic[T]):
|
||||||
def set_args(self, *args: Injection) -> Factory[T]: ...
|
def set_args(self, *args: Injection) -> Factory[T]: ...
|
||||||
def clear_args(self) -> Factory[T]: ...
|
def clear_args(self) -> Factory[T]: ...
|
||||||
@property
|
@property
|
||||||
def kwargs(self) -> Dict[str, Injection]: ...
|
def kwargs(self) -> _Dict[str, Injection]: ...
|
||||||
def add_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
def add_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def set_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
def set_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def clear_kwargs(self) -> Factory[T]: ...
|
def clear_kwargs(self) -> Factory[T]: ...
|
||||||
@property
|
@property
|
||||||
def attributes(self) -> Dict[str, Injection]: ...
|
def attributes(self) -> _Dict[str, Injection]: ...
|
||||||
def add_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
def add_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def set_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
def set_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def clear_attributes(self) -> Factory[T]: ...
|
def clear_attributes(self) -> Factory[T]: ...
|
||||||
|
@ -201,7 +201,7 @@ class FactoryAggregate(Provider):
|
||||||
def __call__(self, factory_name: str, *args: Injection, **kwargs: Injection) -> Any: ...
|
def __call__(self, factory_name: str, *args: Injection, **kwargs: Injection) -> Any: ...
|
||||||
def __getattr__(self, factory_name: str) -> Factory: ...
|
def __getattr__(self, factory_name: str) -> Factory: ...
|
||||||
@property
|
@property
|
||||||
def factories(self) -> Dict[str, Factory]: ...
|
def factories(self) -> _Dict[str, Factory]: ...
|
||||||
|
|
||||||
|
|
||||||
class BaseSingleton(Provider, Generic[T]):
|
class BaseSingleton(Provider, Generic[T]):
|
||||||
|
@ -216,12 +216,12 @@ class BaseSingleton(Provider, Generic[T]):
|
||||||
def set_args(self, *args: Injection) -> Factory[T]: ...
|
def set_args(self, *args: Injection) -> Factory[T]: ...
|
||||||
def clear_args(self) -> Factory[T]: ...
|
def clear_args(self) -> Factory[T]: ...
|
||||||
@property
|
@property
|
||||||
def kwargs(self) -> Dict[str, Injection]: ...
|
def kwargs(self) -> _Dict[str, Injection]: ...
|
||||||
def add_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
def add_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def set_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
def set_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def clear_kwargs(self) -> Factory[T]: ...
|
def clear_kwargs(self) -> Factory[T]: ...
|
||||||
@property
|
@property
|
||||||
def attributes(self) -> Dict[str, Injection]: ...
|
def attributes(self) -> _Dict[str, Injection]: ...
|
||||||
def add_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
def add_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def set_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
def set_attributes(self, **kwargs: Injection) -> Factory[T]: ...
|
||||||
def clear_attributes(self) -> Factory[T]: ...
|
def clear_attributes(self) -> Factory[T]: ...
|
||||||
|
@ -264,6 +264,16 @@ class List(Provider):
|
||||||
def clear_args(self) -> List: ...
|
def clear_args(self) -> List: ...
|
||||||
|
|
||||||
|
|
||||||
|
class Dict(Provider):
|
||||||
|
def __init__(self, **kwargs: Injection): ...
|
||||||
|
def __call__(self, *args: Injection, **kwargs: Injection) -> _Dict[Any, Any]: ...
|
||||||
|
@property
|
||||||
|
def kwargs(self) -> _Dict[Any, Injection]: ...
|
||||||
|
def add_kwargs(self, **kwargs: Injection) -> Dict: ...
|
||||||
|
def set_kwargs(self, **kwargs: Injection) -> Dict: ...
|
||||||
|
def clear_kwargs(self) -> Dict: ...
|
||||||
|
|
||||||
|
|
||||||
class Container(Provider):
|
class Container(Provider):
|
||||||
|
|
||||||
def __init__(self, container_cls: Type[T], container: Optional[T] = None, **overriding_providers: Provider) -> None: ...
|
def __init__(self, container_cls: Type[T], container: Optional[T] = None, **overriding_providers: Provider) -> None: ...
|
||||||
|
@ -278,7 +288,7 @@ class Selector(Provider):
|
||||||
def __call__(self, *args: Injection, **kwargs: Injection) -> Any: ...
|
def __call__(self, *args: Injection, **kwargs: Injection) -> Any: ...
|
||||||
def __getattr__(self, name: str) -> Provider: ...
|
def __getattr__(self, name: str) -> Provider: ...
|
||||||
@property
|
@property
|
||||||
def providers(self) -> Dict[str, Provider]: ...
|
def providers(self) -> _Dict[str, Provider]: ...
|
||||||
|
|
||||||
|
|
||||||
class ProvidedInstanceFluentInterface:
|
class ProvidedInstanceFluentInterface:
|
||||||
|
@ -315,7 +325,7 @@ def is_delegated(instance: Any) -> bool: ...
|
||||||
def represent_provider(provider: Provider, provides: Any) -> str: ...
|
def represent_provider(provider: Provider, provides: Any) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
def deepcopy(instance: Any, memo: Optional[Dict[Any, Any]]): Any: ...
|
def deepcopy(instance: Any, memo: Optional[_Dict[Any, Any]] = None): Any: ...
|
||||||
|
|
||||||
|
|
||||||
def merge_dicts(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]: ...
|
def merge_dicts(dict1: _Dict[Any, Any], dict2: _Dict[Any, Any]) -> _Dict[Any, Any]: ...
|
||||||
|
|
|
@ -2449,6 +2449,84 @@ cdef class List(Provider):
|
||||||
return list(__provide_positional_args(args, self.__args, self.__args_len))
|
return list(__provide_positional_args(args, self.__args, self.__args_len))
|
||||||
|
|
||||||
|
|
||||||
|
cdef class Dict(Provider):
|
||||||
|
"""Dict provider provides a dictionary of values.
|
||||||
|
|
||||||
|
TBD.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
"""Initializer."""
|
||||||
|
self.__kwargs = tuple()
|
||||||
|
self.__kwargs_len = 0
|
||||||
|
self.set_kwargs(**kwargs)
|
||||||
|
super(Dict, self).__init__()
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
"""Create and return full copy of provider."""
|
||||||
|
copied = memo.get(id(self))
|
||||||
|
if copied is not None:
|
||||||
|
return copied
|
||||||
|
|
||||||
|
copied = self.__class__(**deepcopy(self.kwargs, memo))
|
||||||
|
self._copy_overridings(copied, memo)
|
||||||
|
|
||||||
|
return copied
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Return string representation of provider.
|
||||||
|
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return represent_provider(provider=self, provides=dict(self.kwargs))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def kwargs(self):
|
||||||
|
"""Return keyword argument injections."""
|
||||||
|
cdef int index
|
||||||
|
cdef NamedInjection kwarg
|
||||||
|
cdef dict kwargs
|
||||||
|
|
||||||
|
kwargs = dict()
|
||||||
|
for index in range(self.__kwargs_len):
|
||||||
|
kwarg = self.__kwargs[index]
|
||||||
|
kwargs[kwarg.__name] = kwarg.__value
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
def add_kwargs(self, **kwargs):
|
||||||
|
"""Add keyword argument injections.
|
||||||
|
|
||||||
|
:return: Reference ``self``
|
||||||
|
"""
|
||||||
|
self.__kwargs += parse_named_injections(kwargs)
|
||||||
|
self.__kwargs_len = len(self.__kwargs)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def set_kwargs(self, **kwargs):
|
||||||
|
"""Set keyword argument injections.
|
||||||
|
|
||||||
|
Existing keyword argument injections are dropped.
|
||||||
|
|
||||||
|
:return: Reference ``self``
|
||||||
|
"""
|
||||||
|
self.__kwargs = parse_named_injections(kwargs)
|
||||||
|
self.__kwargs_len = len(self.__kwargs)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def clear_kwargs(self):
|
||||||
|
"""Drop keyword argument injections.
|
||||||
|
|
||||||
|
:return: Reference ``self``
|
||||||
|
"""
|
||||||
|
self.__kwargs = tuple()
|
||||||
|
self.__kwargs_len = len(self.__kwargs)
|
||||||
|
return self
|
||||||
|
|
||||||
|
cpdef object _provide(self, tuple args, dict kwargs):
|
||||||
|
"""Return result of provided callable's call."""
|
||||||
|
return __provide_keyword_args(kwargs, self.__kwargs, self.__kwargs_len)
|
||||||
|
|
||||||
|
|
||||||
cdef class Container(Provider):
|
cdef class Container(Provider):
|
||||||
"""Container provider provides an instance of declarative container.
|
"""Container provider provides an instance of declarative container.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user