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
12 changes: 6 additions & 6 deletions injection/_core/common/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
)


def get_return_hint[T](function: Callable[..., T]) -> InputType[T] | None:
def get_return_type[T](function: Callable[..., T]) -> Any | None:
return get_type_hints(function).get("return")


def get_yield_hints[T](
def get_yield_types[T](
function: Callable[..., Iterator[T]] | Callable[..., AsyncIterator[T]],
) -> tuple[InputType[T]] | tuple[()]:
return_type = get_return_hint(function)
) -> tuple[Any] | tuple[()]:
return_type = get_return_type(function)

if get_origin(return_type) in (
AsyncGenerator,
Expand All @@ -62,8 +62,8 @@ def iter_flat_types(*args: Any) -> Iterator[Any]:

def iter_return_types(*args: Any) -> Iterator[Any]:
for arg in args:
if isfunction(arg) and (return_type := get_return_hint(arg)):
yield from iter_return_types(return_type)
if isfunction(arg) and (return_type := get_return_type(arg)):
yield return_type

else:
yield arg
14 changes: 7 additions & 7 deletions injection/_core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from injection._core.common.type import (
InputType,
TypeInfo,
get_yield_hints,
get_yield_types,
iter_flat_types,
iter_return_types,
)
Expand Down Expand Up @@ -264,14 +264,14 @@ def decorator(
if isasyncgenfunction(wrapped):
ctx = _ScopedContext(
cls=AsyncCMScopedInjectable,
hints=() if ignore_type_hint else get_yield_hints(wrapped),
hints=() if ignore_type_hint else get_yield_types(wrapped),
wrapper=asynccontextmanager(wrapped),
)

elif isgeneratorfunction(wrapped):
ctx = _ScopedContext(
cls=CMScopedInjectable,
hints=() if ignore_type_hint else get_yield_hints(wrapped),
hints=() if ignore_type_hint else get_yield_types(wrapped),
wrapper=contextmanager(wrapped),
)

Expand Down Expand Up @@ -713,19 +713,19 @@ def default(cls) -> Module:
return cls.from_name("__default__")

@staticmethod
def __build_key_types(input_cls: Any) -> frozenset[Any]:
def __build_key_types(input_class: Any) -> frozenset[Any]:
config = MatchingTypesConfig(ignore_none=True)
return frozenset(
matching_type
for cls in iter_flat_types(input_cls)
for cls in iter_flat_types(input_class)
for return_type in iter_return_types(cls)
for matching_type in iter_matching_types(return_type, config)
)

@staticmethod
def __matching_key_types(input_cls: Any) -> tuple[Any, ...]:
def __matching_key_types(input_class: Any) -> tuple[Any, ...]:
config = MatchingTypesConfig(with_origin=True, with_type_alias_value=True)
return matching_types(input_cls, config)
return matching_types(input_class, config)


def mod(name: str | None = None, /) -> Module:
Expand Down
7 changes: 5 additions & 2 deletions injection/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@ def __is_empty(self) -> bool:
return not self.module_subsets

def required_module_names(self, name: str | None = None, /) -> frozenset[str]:
names = {n for n in (self.module.name, name) if n is not None}
subsets = (self.__walk_subsets_for(name) for name in names)
subsets = (
self.__walk_subsets_for(module_name)
for module_name in (self.module.name, name)
if module_name is not None
)
return frozenset(itertools.chain.from_iterable(subsets))

def init(self) -> Self:
Expand Down
44 changes: 22 additions & 22 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading