Skip to content
Open
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
13 changes: 10 additions & 3 deletions src/inject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ def my_config(binder):
Injectable = t.Union[object, t.Any]
T = t.TypeVar("T", bound=Injectable)
Binding = t.Union[type[Injectable], t.Hashable]
Constructor = t.Callable[[], Injectable]
Constructor = t.Callable[
[],
t.Union[
Injectable,
contextlib.AbstractContextManager[Injectable],
contextlib.AbstractAsyncContextManager[Injectable],
],
]
Provider = Constructor
BinderCallable = t.Callable[["Binder"], t.Optional["Binder"]]

Expand Down Expand Up @@ -411,7 +418,7 @@ def _aggregate_sync_stack(
param: sync_stack.enter_context(inst)
for param, inst in kwargs.items()
if param not in provided_params
and isinstance(inst, contextlib._GeneratorContextManager) # noqa: SLF001
and isinstance(inst, contextlib.AbstractContextManager)
}
kwargs.update(executed_kwargs)

Expand All @@ -426,7 +433,7 @@ async def _aggregate_async_stack(
param: await async_stack.enter_async_context(inst)
for param, inst in kwargs.items()
if param not in provided_params
and isinstance(inst, contextlib._AsyncGeneratorContextManager) # noqa: SLF001
and isinstance(inst, contextlib.AbstractAsyncContextManager)
}
kwargs.update(executed_kwargs)

Expand Down
Loading