Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions injection/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ from ._core.locator import ModeStr
from ._core.module import PriorityStr
from ._core.scope import ScopeKindStr

type _Decorator[T] = Callable[[T], T]

__MODULE: Final[Module] = ...

afind_instance = __MODULE.afind_instance
aget_instance = __MODULE.aget_instance
aget_lazy_instance = __MODULE.aget_lazy_instance
constant = __MODULE.constant
find_instance = __MODULE.find_instance
get_instance = __MODULE.get_instance
get_lazy_instance = __MODULE.get_lazy_instance
inject = __MODULE.inject
injectable = __MODULE.injectable
reserve_scoped_slot = __MODULE.reserve_scoped_slot
scoped = __MODULE.scoped
set_constant = __MODULE.set_constant
should_be_injectable = __MODULE.should_be_injectable
singleton = __MODULE.singleton
class _Decorator(Protocol):
def __call__[T](self, wrapped: T, /) -> T: ...

_default_module: Final[Module] = ...

afind_instance = _default_module.afind_instance
aget_instance = _default_module.aget_instance
aget_lazy_instance = _default_module.aget_lazy_instance
constant = _default_module.constant
find_instance = _default_module.find_instance
get_instance = _default_module.get_instance
get_lazy_instance = _default_module.get_lazy_instance
inject = _default_module.inject
injectable = _default_module.injectable
reserve_scoped_slot = _default_module.reserve_scoped_slot
scoped = _default_module.scoped
set_constant = _default_module.set_constant
should_be_injectable = _default_module.should_be_injectable
singleton = _default_module.singleton

@overload
def asfunction[**P, T](
Expand Down Expand Up @@ -173,7 +174,7 @@ class Module:
/,
*,
threadsafe: bool | None = ...,
) -> _Decorator: ... # type: ignore[type-arg]
) -> _Decorator: ...
@overload
def injectable[T](
self,
Expand Down Expand Up @@ -201,7 +202,7 @@ class Module:
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
) -> _Decorator: ... # type: ignore[type-arg]
) -> _Decorator: ...
@overload
def singleton[T](
self,
Expand All @@ -227,7 +228,7 @@ class Module:
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
) -> _Decorator: ... # type: ignore[type-arg]
) -> _Decorator: ...
def scoped(
self,
scope_name: str,
Expand All @@ -236,7 +237,7 @@ class Module:
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
) -> _Decorator: # type: ignore[type-arg]
) -> _Decorator:
"""
Decorator applicable to a class or function or generator function. It is used
to indicate how the scoped instance will be constructed. At injection time, the
Expand All @@ -256,7 +257,7 @@ class Module:
self,
wrapped: None = ...,
/,
) -> _Decorator: ... # type: ignore[type-arg]
) -> _Decorator: ...
@overload
def constant[T](
self,
Expand All @@ -280,7 +281,7 @@ class Module:
*,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
) -> _Decorator: ... # type: ignore[type-arg]
) -> _Decorator: ...
def set_constant[T](
self,
instance: T,
Expand Down
2 changes: 1 addition & 1 deletion injection/_core/asfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class _AsFunctionCallable[**P, T](Protocol):
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: ...
def __call__(self, /, *args: P.args, **kwargs: P.kwargs) -> T: ...


type AsFunctionWrappedType[**P, T] = type[_AsFunctionCallable[P, T]]
Expand Down
10 changes: 5 additions & 5 deletions injection/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]


class EntrypointDecorator[**P, T1, T2](Protocol):
class _EntrypointDecorator[**P, T1, T2](Protocol):
if TYPE_CHECKING: # pragma: no cover

@overload
Expand Down Expand Up @@ -62,7 +62,7 @@ def entrypointmaker[**SMP, **EPP, T1, T2](
/,
*,
profile_loader: ProfileLoader = ...,
) -> EntrypointDecorator[EPP, T1, T2]: ...
) -> _EntrypointDecorator[EPP, T1, T2]: ...

@overload
def entrypointmaker[**SMP, **EPP, T1, T2](
Expand All @@ -72,7 +72,7 @@ def entrypointmaker[**SMP, **EPP, T1, T2](
profile_loader: ProfileLoader = ...,
) -> Callable[
[EntrypointSetupMethod[SMP, EPP, T1, T2]],
EntrypointDecorator[EPP, T1, T2],
_EntrypointDecorator[EPP, T1, T2],
]: ...


Expand All @@ -84,7 +84,7 @@ def entrypointmaker[**SMP, **EPP, T1, T2](
) -> Any:
def decorator(
wp: EntrypointSetupMethod[SMP, EPP, T1, T2],
) -> EntrypointDecorator[EPP, T1, T2]:
) -> _EntrypointDecorator[EPP, T1, T2]:
return Entrypoint._make_decorator(wp, profile_loader)

return decorator(wrapped) if wrapped else decorator
Expand Down Expand Up @@ -173,7 +173,7 @@ def _make_decorator[**_P, _T](
setup_method: EntrypointSetupMethod[_P, P, T, _T],
/,
profile_loader: ProfileLoader | None = None,
) -> EntrypointDecorator[P, T, _T]:
) -> _EntrypointDecorator[P, T, _T]:
profile_loader = profile_loader or ProfileLoader()
setup_method = profile_loader.module.make_injected_function(setup_method)

Expand Down
Loading