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
175 changes: 93 additions & 82 deletions injection/_core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from logging import Logger, getLogger
from types import MethodType
from typing import (
TYPE_CHECKING,
Any,
AsyncContextManager,
ClassVar,
Expand Down Expand Up @@ -577,21 +578,23 @@ def decorator(wp: Callable[P, T]) -> Callable[P, T]:

return decorator(wrapped) if wrapped else decorator

@overload
def make_injected_function[**P, T](
self,
wrapped: Callable[P, T],
/,
threadsafe: bool | None = ...,
) -> SyncInjectedFunction[P, T]: ...
if TYPE_CHECKING: # pragma: no cover

@overload
def make_injected_function[**P, T](
self,
wrapped: Callable[P, Awaitable[T]],
/,
threadsafe: bool | None = ...,
) -> AsyncInjectedFunction[P, T]: ...
@overload
def make_injected_function[**P, T](
self,
wrapped: Callable[P, T],
/,
threadsafe: bool | None = ...,
) -> SyncInjectedFunction[P, T]: ...

@overload
def make_injected_function[**P, T](
self,
wrapped: Callable[P, Awaitable[T]],
/,
threadsafe: bool | None = ...,
) -> AsyncInjectedFunction[P, T]: ...

def make_injected_function[**P, T](
self,
Expand Down Expand Up @@ -643,23 +646,25 @@ def find_instance[T](
injectable = self[cls]
return injectable.get_instance()

@overload
async def aget_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> T | Default: ...

@overload
async def aget_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> T: ...
if TYPE_CHECKING: # pragma: no cover

@overload
async def aget_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> T | Default: ...

@overload
async def aget_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> T: ...

async def aget_instance[T, Default](
self,
Expand All @@ -673,23 +678,25 @@ async def aget_instance[T, Default](
except (KeyError, SkipInjectable):
return default

@overload
def get_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> T | Default: ...

@overload
def get_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> T: ...
if TYPE_CHECKING: # pragma: no cover

@overload
def get_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> T | Default: ...

@overload
def get_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> T: ...

def get_instance[T, Default](
self,
Expand All @@ -703,23 +710,25 @@ def get_instance[T, Default](
except (KeyError, SkipInjectable):
return default

@overload
def aget_lazy_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> Awaitable[T | Default]: ...

@overload
def aget_lazy_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> Awaitable[T]: ...
if TYPE_CHECKING: # pragma: no cover

@overload
def aget_lazy_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> Awaitable[T | Default]: ...

@overload
def aget_lazy_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> Awaitable[T]: ...

def aget_lazy_instance[T, Default](
self,
Expand All @@ -735,23 +744,25 @@ def aget_lazy_instance[T, Default](
metadata = function.__inject_metadata__.set_owner(cls)
return SimpleAwaitable(metadata.acall)

@overload
def get_lazy_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> Invertible[T | Default]: ...

@overload
def get_lazy_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> Invertible[T]: ...
if TYPE_CHECKING: # pragma: no cover

@overload
def get_lazy_instance[T, Default](
self,
cls: InputType[T],
default: Default,
*,
threadsafe: bool | None = ...,
) -> Invertible[T | Default]: ...

@overload
def get_lazy_instance[T](
self,
cls: InputType[T],
default: T = ...,
*,
threadsafe: bool | None = ...,
) -> Invertible[T]: ...

def get_lazy_instance[T, Default](
self,
Expand Down
10 changes: 6 additions & 4 deletions injection/_core/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from enum import StrEnum
from types import EllipsisType, TracebackType
from typing import (
TYPE_CHECKING,
Any,
AsyncContextManager,
ContextManager,
Expand Down Expand Up @@ -158,12 +159,13 @@ def get_active_scopes(name: str) -> tuple[Scope, ...]:
return tuple(itertools.chain.from_iterable(active_scopes))


@overload
def get_scope(name: str, default: EllipsisType = ...) -> Scope: ...
if TYPE_CHECKING: # pragma: no cover

@overload
def get_scope(name: str, default: EllipsisType = ...) -> Scope: ...

@overload
def get_scope[T](name: str, default: T) -> Scope | T: ...
@overload
def get_scope[T](name: str, default: T) -> Scope | T: ...


def get_scope[T](name: str, default: T | EllipsisType = ...) -> Scope | T:
Expand Down
48 changes: 24 additions & 24 deletions injection/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import wraps
from types import MethodType
from types import ModuleType as PythonModule
from typing import Any, Concatenate, Self, final, overload
from typing import TYPE_CHECKING, Any, Concatenate, Self, final, overload

from injection import Module
from injection.loaders import ProfileLoader, PythonModuleLoader
Expand All @@ -21,13 +21,13 @@
Entrypoint[EPP, T2],
]

if TYPE_CHECKING: # pragma: no cover

@overload
def autocall[T: Callable[..., Any]](wrapped: T, /) -> T: ...
@overload
def autocall[T: Callable[..., Any]](wrapped: T, /) -> T: ...


@overload
def autocall[T: Callable[..., Any]](wrapped: None = ..., /) -> Callable[[T], T]: ...
@overload
def autocall[T: Callable[..., Any]](wrapped: None = ..., /) -> Callable[[T], T]: ...


def autocall[T: Callable[..., Any]](
Expand All @@ -44,26 +44,26 @@ def decorator(wp: T) -> T:
# SMP = Setup Method Parameters
# EPP = EntryPoint Parameters

if TYPE_CHECKING: # pragma: no cover

@overload
def entrypointmaker[**SMP, **EPP, T1, T2](
wrapped: EntrypointSetupMethod[SMP, EPP, T1, T2],
/,
*,
profile_loader: ProfileLoader = ...,
) -> EntrypointDecorator[EPP, T1, T2]: ...

@overload
def entrypointmaker[**SMP, **EPP, T1, T2](
wrapped: EntrypointSetupMethod[SMP, EPP, T1, T2],
/,
*,
profile_loader: ProfileLoader = ...,
) -> EntrypointDecorator[EPP, T1, T2]: ...

@overload
def entrypointmaker[**SMP, **EPP, T1, T2](
wrapped: None = ...,
/,
*,
profile_loader: ProfileLoader = ...,
) -> Callable[
[EntrypointSetupMethod[SMP, EPP, T1, T2]],
EntrypointDecorator[EPP, T1, T2],
]: ...
@overload
def entrypointmaker[**SMP, **EPP, T1, T2](
wrapped: None = ...,
/,
*,
profile_loader: ProfileLoader = ...,
) -> Callable[
[EntrypointSetupMethod[SMP, EPP, T1, T2]],
EntrypointDecorator[EPP, T1, T2],
]: ...


def entrypointmaker[**SMP, **EPP, T1, T2](
Expand Down
Loading