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
7 changes: 7 additions & 0 deletions injection/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Module:
/,
*,
cls: _InjectableFactory[Any] = ...,
ignore_type_hint: bool = ...,
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
Expand All @@ -199,6 +200,7 @@ class Module:
/,
*,
cls: _InjectableFactory[Any] = ...,
ignore_type_hint: bool = ...,
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
Expand All @@ -209,6 +211,7 @@ class Module:
wrapped: T,
/,
*,
ignore_type_hint: bool = ...,
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
Expand All @@ -225,6 +228,7 @@ class Module:
wrapped: None = ...,
/,
*,
ignore_type_hint: bool = ...,
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
Expand All @@ -234,6 +238,7 @@ class Module:
scope_name: str,
/,
*,
ignore_type_hint: bool = ...,
inject: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
Expand Down Expand Up @@ -264,6 +269,7 @@ class Module:
wrapped: T,
/,
*,
ignore_type_hint: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
) -> T:
Expand All @@ -279,6 +285,7 @@ class Module:
wrapped: None = ...,
/,
*,
ignore_type_hint: bool = ...,
on: _TypeInfo[Any] = ...,
mode: Mode | ModeStr = ...,
) -> _Decorator: ...
Expand Down
12 changes: 7 additions & 5 deletions injection/_core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
AsyncIterator,
Awaitable,
Callable,
Collection,
Container,
Generator,
Iterable,
Expand Down Expand Up @@ -180,7 +181,7 @@ def get_default(cls) -> Priority:
@dataclass(repr=False, eq=False, frozen=True, slots=True)
class _ScopedContext[**P, T]:
cls: type[ScopedInjectable[Any, T]]
hints: TypeInfo[T]
hints: Collection[TypeInfo[T]]
wrapper: Recipe[P, T] | ContextManagerRecipe[P, T]


Expand Down Expand Up @@ -266,6 +267,7 @@ def scoped[**P, T](
scope_name: str,
/,
*,
ignore_type_hint: bool = False,
inject: bool = True,
on: TypeInfo[T] = (),
mode: Mode | ModeStr = Mode.get_default(),
Expand All @@ -276,21 +278,21 @@ def decorator(
if isasyncgenfunction(wrapped):
ctx = _ScopedContext(
cls=AsyncCMScopedInjectable,
hints=get_yield_hints(wrapped),
hints=() if ignore_type_hint else get_yield_hints(wrapped),
wrapper=asynccontextmanager(wrapped),
)

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

else:
ctx = _ScopedContext(
cls=SimpleScopedInjectable,
hints=(wrapped,),
hints=() if ignore_type_hint else (wrapped,),
wrapper=wrapped,
)

Expand All @@ -299,7 +301,7 @@ def decorator(
cls=ctx.cls.bind_scope_name(scope_name),
ignore_type_hint=True,
inject=inject,
on=(ctx.hints, on),
on=(*ctx.hints, on),
mode=mode,
)
return wrapped
Expand Down
Loading