Skip to content

Commit 45c3a76

Browse files
authored
refactoring: ♻️ Small changes
1 parent 18c2b3c commit 45c3a76

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

injection/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class Module:
136136
137137
With `threadsafe=True`, the injection logic is wrapped in a `threading.RLock`.
138138
"""
139+
139140
@overload
140141
def inject[T](
141142
self,

injection/_core/common/type.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ def get_return_hint[T](function: Callable[..., T]) -> InputType[T] | None:
5454

5555
def get_yield_hint[T](
5656
function: Callable[..., Iterator[T]] | Callable[..., AsyncIterator[T]],
57-
) -> InputType[T] | None:
57+
) -> tuple[InputType[T]] | tuple[()]:
5858
return_type = get_return_hint(function)
5959

60-
if get_origin(return_type) not in {
60+
if get_origin(return_type) in {
6161
AsyncGenerator,
6262
AsyncIterable,
6363
AsyncIterator,
6464
Generator,
6565
Iterable,
6666
Iterator,
6767
}:
68-
return None
68+
for arg in get_args(return_type):
69+
return (arg,)
6970

70-
args = get_args(return_type)
71-
return next(iter(args), None)
71+
return ()
7272

7373

7474
def standardize_types(

injection/_core/module.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,14 @@ def __keep_new_record[T](
337337
cls: InputType[T],
338338
) -> bool:
339339
new_mode, existing_mode = new.mode, existing.mode
340-
is_override = new_mode == Mode.OVERRIDE
341340

342-
if new_mode == existing_mode and not is_override:
341+
if new_mode == Mode.OVERRIDE:
342+
return True
343+
344+
elif new_mode == existing_mode:
343345
raise RuntimeError(f"An injectable already exists for the class `{cls}`.")
344346

345-
return is_override or new_mode.rank > existing_mode.rank
347+
return new_mode.rank > existing_mode.rank
346348

347349
@staticmethod
348350
def __standardize_inputs[T](
@@ -478,16 +480,16 @@ def decorator(
478480
wrapper = contextmanager(wrapped)
479481

480482
else:
483+
hint = (wrapped,) # type: ignore[assignment]
481484
injectable_class = SimpleScopedInjectable
482-
hint = wrapper = wrapped # type: ignore[assignment]
485+
wrapper = wrapped # type: ignore[assignment]
483486

484-
hints = on if hint is None else (hint, on)
485487
self.injectable(
486488
wrapper,
487489
cls=partial(injectable_class, scope_name=scope_name),
488490
ignore_type_hint=True,
489491
inject=inject,
490-
on=hints,
492+
on=(*hint, on),
491493
mode=mode,
492494
)
493495
return wrapped

uv.lock

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

0 commit comments

Comments
 (0)