|
| 1 | +from collections.abc import Callable |
| 2 | +from enum import Enum |
| 3 | +from typing import Any, Generic, NamedTuple, TypeVar, overload |
| 4 | + |
| 5 | +__version__: str |
| 6 | + |
| 7 | +class MissingDependencyException(Exception): ... |
| 8 | +class MissingDependencyError(MissingDependencyException): ... |
| 9 | +class InvalidRegistrationException(Exception): ... |
| 10 | +class InvalidRegistrationError(InvalidRegistrationException): ... |
| 11 | +class InvalidForwardReferenceException(Exception): ... |
| 12 | +class InvalidForwardReferenceError(InvalidForwardReferenceException): ... |
| 13 | + |
| 14 | +class Scope(Enum): |
| 15 | + transient = 0 |
| 16 | + singleton = 1 |
| 17 | + |
| 18 | +_T = TypeVar("_T") |
| 19 | +_TOpt = TypeVar("_TOpt", default=object) |
| 20 | + |
| 21 | +class _Registration(NamedTuple, Generic[_T]): |
| 22 | + service: type[_T] | str |
| 23 | + scope: Scope |
| 24 | + builder: Callable[[], _T] |
| 25 | + needs: dict[str, object] |
| 26 | + args: dict[str, object] |
| 27 | + |
| 28 | +empty: Any |
| 29 | + |
| 30 | +class _Registry: |
| 31 | + def register_service_and_impl( |
| 32 | + self, service: type | str, scope: Scope, impl: Callable[..., object], resolve_args: dict[str, object] |
| 33 | + ) -> None: ... |
| 34 | + def register_service_and_instance(self, service: type[_T] | str, instance: _T) -> None: ... |
| 35 | + def register_concrete_service(self, service: type | str, scope: Scope) -> None: ... |
| 36 | + def build_context(self, key: type | str, existing: _ResolutionContext | None = None) -> _ResolutionContext: ... |
| 37 | + def register( |
| 38 | + self, service: type[_T] | str, factory: Callable[..., _T] = ..., instance: _T = ..., scope: Scope = ..., **kwargs: object |
| 39 | + ) -> None: ... |
| 40 | + def __getitem__(self, service: type[_T] | str) -> list[_Registration[_T]]: ... |
| 41 | + |
| 42 | +class _ResolutionTarget(Generic[_T]): |
| 43 | + service: type[_T] | str |
| 44 | + impls: list[_Registration[_T]] |
| 45 | + def __init__(self, key: type[_T] | str, impls: list[_Registration[_T]]) -> None: ... |
| 46 | + def is_generic_list(self) -> bool: ... |
| 47 | + @property |
| 48 | + def generic_parameter(self) -> Any: ... |
| 49 | + def next_impl(self) -> _Registration[_T]: ... |
| 50 | + |
| 51 | +class _ResolutionContext: |
| 52 | + targets: dict[type | str, _ResolutionTarget[object]] |
| 53 | + cache: dict[type | str, object] |
| 54 | + service: type | str |
| 55 | + def __init__(self, key: type | str, impls: list[_Registration[object]]) -> None: ... |
| 56 | + def target(self, key: type[_T] | str) -> _ResolutionTarget[_T]: ... |
| 57 | + def has_cached(self, key: type | str) -> bool: ... |
| 58 | + def __getitem__(self, key: type | str) -> object: ... |
| 59 | + def __setitem__(self, key: type | str, value: object) -> None: ... |
| 60 | + def all_registrations(self, service: type[_T] | str) -> list[_Registration[_T]]: ... |
| 61 | + |
| 62 | +class Container: |
| 63 | + registrations: _Registry |
| 64 | + def __init__(self) -> None: ... |
| 65 | + @overload |
| 66 | + def register(self, service: type[_TOpt] | str, *, instance: _TOpt, **kwargs: Any) -> Container: ... |
| 67 | + @overload |
| 68 | + def register( |
| 69 | + self, service: type[_TOpt] | str, factory: Callable[..., _TOpt] = ..., *, scope: Scope = ..., **kwargs: Any |
| 70 | + ) -> Container: ... |
| 71 | + @overload |
| 72 | + def register( |
| 73 | + self, |
| 74 | + service: type[_TOpt] | str, |
| 75 | + factory: Callable[..., _TOpt] = ..., |
| 76 | + instance: _TOpt = ..., |
| 77 | + scope: Scope = Scope.transient, |
| 78 | + **kwargs: Any, |
| 79 | + ): ... |
| 80 | + def resolve_all(self, service: type[_TOpt] | str, **kwargs: Any) -> list[_TOpt]: ... |
| 81 | + def resolve(self, service_key: type[_TOpt] | str, **kwargs: Any) -> _TOpt: ... |
| 82 | + def instantiate(self, service_key: type[_TOpt] | str, **kwargs: Any) -> _TOpt: ... |
0 commit comments