mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 09:57:37 +03:00 
			
		
		
		
	Refactor provider typing stubs
This commit is contained in:
		
							parent
							
								
									cb2a36b216
								
							
						
					
					
						commit
						f1256a44fd
					
				| 
						 | 
				
			
			@ -66,44 +66,24 @@ class Provider(Generic[T]):
 | 
			
		|||
    def _copy_overridings(self, copied: Provider, memo: Optional[_Dict[Any, Any]]) -> None: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Object(Provider, Generic[T]):
 | 
			
		||||
class Object(Provider[T]):
 | 
			
		||||
    def __init__(self, provides: T) -> None: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Delegate(Provider):
 | 
			
		||||
class Delegate(Provider[Provider]):
 | 
			
		||||
    def __init__(self, provides: Provider) -> None: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Provider: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[Provider]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[Provider]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def provides(self) -> Provider: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Dependency(Provider, Generic[T]):
 | 
			
		||||
class Dependency(Provider[T]):
 | 
			
		||||
    def __init__(self, instance_of: Type[T] = object) -> None: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def instance_of(self) -> Type[T]: ...
 | 
			
		||||
    def provided_by(self, provider: Provider) -> OverridingContext: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ExternalDependency(Dependency): ...
 | 
			
		||||
class ExternalDependency(Dependency[T]): ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DependenciesContainer(Object):
 | 
			
		||||
| 
						 | 
				
			
			@ -113,15 +93,8 @@ class DependenciesContainer(Object):
 | 
			
		|||
    def providers(self) -> _Dict[str, Provider]: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Callable(Provider, Generic[T]):
 | 
			
		||||
class Callable(Provider[T]):
 | 
			
		||||
    def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def provides(self) -> T: ...
 | 
			
		||||
    @property
 | 
			
		||||
| 
						 | 
				
			
			@ -130,16 +103,16 @@ class Callable(Provider, Generic[T]):
 | 
			
		|||
    def set_args(self, *args: Injection) -> Callable[T]: ...
 | 
			
		||||
    def clear_args(self) -> Callable[T]: ...
 | 
			
		||||
    @property
 | 
			
		||||
    def kwargs(self) -> _Dict[str, Injection]: ...
 | 
			
		||||
    def kwargs(self) -> _Dict[Any, Injection]: ...
 | 
			
		||||
    def add_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
 | 
			
		||||
    def set_kwargs(self, **kwargs: Injection) -> Callable[T]: ...
 | 
			
		||||
    def clear_kwargs(self) -> Callable[T]: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DelegatedCallable(Callable): ...
 | 
			
		||||
class DelegatedCallable(Callable[T]): ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AbstractCallable(Callable):
 | 
			
		||||
class AbstractCallable(Callable[T]):
 | 
			
		||||
    def override(self, provider: Callable) -> OverridingContext: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -147,13 +120,13 @@ class CallableDelegate(Delegate):
 | 
			
		|||
    def __init__(self, callable: Callable) -> None: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Coroutine(Callable): ...
 | 
			
		||||
class Coroutine(Callable[T]): ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DelegatedCoroutine(Coroutine): ...
 | 
			
		||||
class DelegatedCoroutine(Coroutine[T]): ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AbstractCoroutine(Coroutine):
 | 
			
		||||
class AbstractCoroutine(Coroutine[T]):
 | 
			
		||||
    def override(self, provider: Coroutine) -> OverridingContext: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -161,18 +134,11 @@ class CoroutineDelegate(Delegate):
 | 
			
		|||
    def __init__(self, coroutine: Coroutine) -> None: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ConfigurationOption(Provider):
 | 
			
		||||
class ConfigurationOption(Provider[Any]):
 | 
			
		||||
    UNDEFINED: object
 | 
			
		||||
    def __init__(self, name: Tuple[str], root: Configuration) -> None: ...
 | 
			
		||||
    def __getattr__(self, item: str) -> ConfigurationOption: ...
 | 
			
		||||
    def __getitem__(self, item: Union[str, Provider]) -> ConfigurationOption: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Any: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def root(self) -> Configuration: ...
 | 
			
		||||
    def get_name(self) -> str: ...
 | 
			
		||||
| 
						 | 
				
			
			@ -192,18 +158,11 @@ class TypedConfigurationOption(Callable[T]):
 | 
			
		|||
    def option(self) -> ConfigurationOption: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Configuration(Object):
 | 
			
		||||
class Configuration(Object[Any]):
 | 
			
		||||
    DEFAULT_NAME: str = 'config'
 | 
			
		||||
    def __init__(self, name: str = DEFAULT_NAME, default: Optional[Any] = None) -> None: ...
 | 
			
		||||
    def __getattr__(self, item: str) -> ConfigurationOption: ...
 | 
			
		||||
    def __getitem__(self, item: Union[str, Provider]) -> ConfigurationOption: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Any: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ...
 | 
			
		||||
 | 
			
		||||
    def get_name(self) -> str: ...
 | 
			
		||||
    def get(self, selector: str) -> Any: ...
 | 
			
		||||
    def set(self, selector: str, value: Any) -> OverridingContext: ...
 | 
			
		||||
| 
						 | 
				
			
			@ -215,16 +174,9 @@ class Configuration(Object):
 | 
			
		|||
    def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Factory(Provider, Generic[T]):
 | 
			
		||||
class Factory(Provider[T]):
 | 
			
		||||
    provided_type: Optional[Type]
 | 
			
		||||
    def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def cls(self) -> T: ...
 | 
			
		||||
    @property
 | 
			
		||||
| 
						 | 
				
			
			@ -235,21 +187,21 @@ class Factory(Provider, Generic[T]):
 | 
			
		|||
    def set_args(self, *args: Injection) -> Factory[T]: ...
 | 
			
		||||
    def clear_args(self) -> Factory[T]: ...
 | 
			
		||||
    @property
 | 
			
		||||
    def kwargs(self) -> _Dict[str, Injection]: ...
 | 
			
		||||
    def kwargs(self) -> _Dict[Any, Injection]: ...
 | 
			
		||||
    def add_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
 | 
			
		||||
    def set_kwargs(self, **kwargs: Injection) -> Factory[T]: ...
 | 
			
		||||
    def clear_kwargs(self) -> Factory[T]: ...
 | 
			
		||||
    @property
 | 
			
		||||
    def attributes(self) -> _Dict[str, Injection]: ...
 | 
			
		||||
    def attributes(self) -> _Dict[Any, Injection]: ...
 | 
			
		||||
    def add_attributes(self, **kwargs: Injection) -> Factory[T]: ...
 | 
			
		||||
    def set_attributes(self, **kwargs: Injection) -> Factory[T]: ...
 | 
			
		||||
    def clear_attributes(self) -> Factory[T]: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DelegatedFactory(Factory): ...
 | 
			
		||||
class DelegatedFactory(Factory[T]): ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AbstractFactory(Factory):
 | 
			
		||||
class AbstractFactory(Factory[T]):
 | 
			
		||||
    def override(self, provider: Factory) -> OverridingContext: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -271,16 +223,9 @@ class FactoryAggregate(Provider):
 | 
			
		|||
    def factories(self) -> _Dict[str, Factory]: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BaseSingleton(Provider, Generic[T]):
 | 
			
		||||
class BaseSingleton(Provider[T]):
 | 
			
		||||
    provided_type = Optional[Type]
 | 
			
		||||
    def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def cls(self) -> T: ...
 | 
			
		||||
    @property
 | 
			
		||||
| 
						 | 
				
			
			@ -289,12 +234,12 @@ class BaseSingleton(Provider, Generic[T]):
 | 
			
		|||
    def set_args(self, *args: Injection) -> BaseSingleton[T]: ...
 | 
			
		||||
    def clear_args(self) -> BaseSingleton[T]: ...
 | 
			
		||||
    @property
 | 
			
		||||
    def kwargs(self) -> _Dict[str, Injection]: ...
 | 
			
		||||
    def kwargs(self) -> _Dict[Any, Injection]: ...
 | 
			
		||||
    def add_kwargs(self, **kwargs: Injection) -> BaseSingleton[T]: ...
 | 
			
		||||
    def set_kwargs(self, **kwargs: Injection) -> BaseSingleton[T]: ...
 | 
			
		||||
    def clear_kwargs(self) -> BaseSingleton[T]: ...
 | 
			
		||||
    @property
 | 
			
		||||
    def attributes(self) -> _Dict[str, Injection]: ...
 | 
			
		||||
    def attributes(self) -> _Dict[Any, Injection]: ...
 | 
			
		||||
    def add_attributes(self, **kwargs: Injection) -> BaseSingleton[T]: ...
 | 
			
		||||
    def set_attributes(self, **kwargs: Injection) -> BaseSingleton[T]: ...
 | 
			
		||||
    def clear_attributes(self) -> BaseSingleton[T]: ...
 | 
			
		||||
| 
						 | 
				
			
			@ -327,31 +272,17 @@ class SingletonDelegate(Delegate):
 | 
			
		|||
    def __init__(self, factory: BaseSingleton): ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class List(Provider):
 | 
			
		||||
class List(Provider[_List]):
 | 
			
		||||
    def __init__(self, *args: Injection): ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> _List[Any]: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[_List[Any]]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[_List[Any]]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def args(self) -> Tuple[Injection]: ...
 | 
			
		||||
    def add_args(self, *args: Injection) -> List: ...
 | 
			
		||||
    def set_args(self, *args: Injection) -> List: ...
 | 
			
		||||
    def clear_args(self) -> List: ...
 | 
			
		||||
    def add_args(self, *args: Injection) -> List[T]: ...
 | 
			
		||||
    def set_args(self, *args: Injection) -> List[T]: ...
 | 
			
		||||
    def clear_args(self) -> List[T]: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Dict(Provider):
 | 
			
		||||
class Dict(Provider[_Dict]):
 | 
			
		||||
    def __init__(self, dict_: Optional[_Dict[Any, Injection]] = None, **kwargs: Injection): ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> _Dict[Any, Any]: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[_Dict[Any, Any]]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[_Dict[Any, Any]]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def kwargs(self) -> _Dict[Any, Injection]: ...
 | 
			
		||||
    def add_kwargs(self, dict_: Optional[_Dict[Any, Injection]] = None, **kwargs: Injection) -> Dict: ...
 | 
			
		||||
| 
						 | 
				
			
			@ -359,7 +290,7 @@ class Dict(Provider):
 | 
			
		|||
    def clear_kwargs(self) -> Dict: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Resource(Provider, Generic[T]):
 | 
			
		||||
class Resource(Provider[T]):
 | 
			
		||||
    @overload
 | 
			
		||||
    def __init__(self, initializer: _Callable[..., resources.Resource[T]], *args: Injection, **kwargs: Injection) -> None: ...
 | 
			
		||||
    @overload
 | 
			
		||||
| 
						 | 
				
			
			@ -372,54 +303,32 @@ class Resource(Provider, Generic[T]):
 | 
			
		|||
    def __init__(self, initializer: _Callable[..., _Coroutine[Injection, Injection, T]], *args: Injection, **kwargs: Injection) -> None: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __init__(self, initializer: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def args(self) -> Tuple[Injection]: ...
 | 
			
		||||
    def add_args(self, *args: Injection) -> Resource: ...
 | 
			
		||||
    def set_args(self, *args: Injection) -> Resource: ...
 | 
			
		||||
    def clear_args(self) -> Resource: ...
 | 
			
		||||
    def add_args(self, *args: Injection) -> Resource[T]: ...
 | 
			
		||||
    def set_args(self, *args: Injection) -> Resource[T]: ...
 | 
			
		||||
    def clear_args(self) -> Resource[T]: ...
 | 
			
		||||
    @property
 | 
			
		||||
    def kwargs(self) -> _Dict[Any, Injection]: ...
 | 
			
		||||
    def add_kwargs(self, **kwargs: Injection) -> Resource: ...
 | 
			
		||||
    def set_kwargs(self, **kwargs: Injection) -> Resource: ...
 | 
			
		||||
    def clear_kwargs(self) -> Resource: ...
 | 
			
		||||
    def add_kwargs(self, **kwargs: Injection) -> Resource[T]: ...
 | 
			
		||||
    def set_kwargs(self, **kwargs: Injection) -> Resource[T]: ...
 | 
			
		||||
    def clear_kwargs(self) -> Resource[T]: ...
 | 
			
		||||
    @property
 | 
			
		||||
    def initialized(self) -> bool: ...
 | 
			
		||||
    def init(self) -> Optional[Awaitable[T]]: ...
 | 
			
		||||
    def shutdown(self) -> Optional[Awaitable]: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Container(Provider):
 | 
			
		||||
 | 
			
		||||
class Container(Provider[T]):
 | 
			
		||||
    def __init__(self, container_cls: Type[T], container: Optional[T] = None, **overriding_providers: Provider) -> None: ...
 | 
			
		||||
    def __getattr__(self, name: str) -> Provider: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> T: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[T]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def container(self) -> T: ...
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Selector(Provider):
 | 
			
		||||
class Selector(Provider[Any]):
 | 
			
		||||
    def __init__(self, selector: _Callable[..., Any], **providers: Provider): ...
 | 
			
		||||
    def __getattr__(self, name: str) -> Provider: ...
 | 
			
		||||
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Any: ...
 | 
			
		||||
    @overload
 | 
			
		||||
    def __call__(self, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ...
 | 
			
		||||
    def async_(self, *args: Injection, **kwargs: Injection) -> Awaitable[Any]: ...
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def providers(self) -> _Dict[str, Provider]: ...
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user