Skip to content

Commit 55db6d8

Browse files
authored
refactor: Enhance readability
1 parent ceb4c9b commit 55db6d8

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

injection/_core/common/type.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
)
2929

3030

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

3434

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

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

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

6868
else:
6969
yield arg

injection/_core/module.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from injection._core.common.type import (
5353
InputType,
5454
TypeInfo,
55-
get_yield_hints,
55+
get_yield_types,
5656
iter_flat_types,
5757
iter_return_types,
5858
)
@@ -264,14 +264,14 @@ def decorator(
264264
if isasyncgenfunction(wrapped):
265265
ctx = _ScopedContext(
266266
cls=AsyncCMScopedInjectable,
267-
hints=() if ignore_type_hint else get_yield_hints(wrapped),
267+
hints=() if ignore_type_hint else get_yield_types(wrapped),
268268
wrapper=asynccontextmanager(wrapped),
269269
)
270270

271271
elif isgeneratorfunction(wrapped):
272272
ctx = _ScopedContext(
273273
cls=CMScopedInjectable,
274-
hints=() if ignore_type_hint else get_yield_hints(wrapped),
274+
hints=() if ignore_type_hint else get_yield_types(wrapped),
275275
wrapper=contextmanager(wrapped),
276276
)
277277

@@ -713,19 +713,19 @@ def default(cls) -> Module:
713713
return cls.from_name("__default__")
714714

715715
@staticmethod
716-
def __build_key_types(input_cls: Any) -> frozenset[Any]:
716+
def __build_key_types(input_class: Any) -> frozenset[Any]:
717717
config = MatchingTypesConfig(ignore_none=True)
718718
return frozenset(
719719
matching_type
720-
for cls in iter_flat_types(input_cls)
720+
for cls in iter_flat_types(input_class)
721721
for return_type in iter_return_types(cls)
722722
for matching_type in iter_matching_types(return_type, config)
723723
)
724724

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

730730

731731
def mod(name: str | None = None, /) -> Module:

injection/loaders.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,11 @@ def __is_empty(self) -> bool:
150150
return not self.module_subsets
151151

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

157160
def init(self) -> Self:

uv.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)