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
1 change: 1 addition & 0 deletions injection/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Module:

With `threadsafe=True`, the injection logic is wrapped in a `threading.RLock`.
"""

@overload
def inject[T](
self,
Expand Down
10 changes: 5 additions & 5 deletions injection/_core/common/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ def get_return_hint[T](function: Callable[..., T]) -> InputType[T] | None:

def get_yield_hint[T](
function: Callable[..., Iterator[T]] | Callable[..., AsyncIterator[T]],
) -> InputType[T] | None:
) -> tuple[InputType[T]] | tuple[()]:
return_type = get_return_hint(function)

if get_origin(return_type) not in {
if get_origin(return_type) in {
AsyncGenerator,
AsyncIterable,
AsyncIterator,
Generator,
Iterable,
Iterator,
}:
return None
for arg in get_args(return_type):
return (arg,)

args = get_args(return_type)
return next(iter(args), None)
return ()


def standardize_types(
Expand Down
14 changes: 8 additions & 6 deletions injection/_core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,14 @@ def __keep_new_record[T](
cls: InputType[T],
) -> bool:
new_mode, existing_mode = new.mode, existing.mode
is_override = new_mode == Mode.OVERRIDE

if new_mode == existing_mode and not is_override:
if new_mode == Mode.OVERRIDE:
return True

elif new_mode == existing_mode:
raise RuntimeError(f"An injectable already exists for the class `{cls}`.")

return is_override or new_mode.rank > existing_mode.rank
return new_mode.rank > existing_mode.rank

@staticmethod
def __standardize_inputs[T](
Expand Down Expand Up @@ -478,16 +480,16 @@ def decorator(
wrapper = contextmanager(wrapped)

else:
hint = (wrapped,) # type: ignore[assignment]
injectable_class = SimpleScopedInjectable
hint = wrapper = wrapped # type: ignore[assignment]
wrapper = wrapped # type: ignore[assignment]

hints = on if hint is None else (hint, on)
self.injectable(
wrapper,
cls=partial(injectable_class, scope_name=scope_name),
ignore_type_hint=True,
inject=inject,
on=hints,
on=(*hint, on),
Comment thread
remimd marked this conversation as resolved.
mode=mode,
)
return wrapped
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

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