Skip to content

Commit

Permalink
Merge pull request #96 from fhdufhdu/master
Browse files Browse the repository at this point in the history
Added context manager condition to attr function(Fix #94)
  • Loading branch information
ivankorobkov authored Mar 24, 2024
2 parents 80f1948 + 189c20d commit e6bc868
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/inject/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,14 @@ def __init__(self, cls: Binding) -> None:
self._cls = cls

def __get__(self, obj: Any, owner: Any) -> Injectable:
return instance(self._cls)
inst = instance(self._cls)
if isinstance(inst, contextlib._AsyncGeneratorContextManager):
raise InjectorException(
'Fail to load _AsyncGeneratorContextManager, Use autoparams, param or params instead of attr funcion')
elif isinstance(inst, contextlib._GeneratorContextManager):
with contextlib.ExitStack() as sync_stack:
inst = sync_stack.enter_context(inst)
return inst


class _AttributeInjectionDataclass(Generic[T]):
Expand Down

0 comments on commit e6bc868

Please sign in to comment.