File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ def my_config(binder):
7373 inject.configure(my_config)
7474
7575"""
76+ import asyncio
7677import contextlib
7778
7879from inject ._version import __version__
@@ -281,7 +282,14 @@ def __init__(self, cls: Binding) -> None:
281282 self ._cls = cls
282283
283284 def __get__ (self , obj : Any , owner : Any ) -> Injectable :
284- return instance (self ._cls )
285+ inst = instance (self ._cls )
286+ if isinstance (inst , contextlib ._AsyncGeneratorContextManager ):
287+ raise InjectorException (
288+ 'Fail to load _AsyncGeneratorContextManager, Use autoparams, param or params instead of attr funcion' )
289+ elif isinstance (inst , contextlib ._GeneratorContextManager ):
290+ with contextlib .ExitStack () as sync_stack :
291+ inst = sync_stack .enter_context (inst )
292+ return inst
285293
286294
287295class _AttributeInjectionDataclass (Generic [T ]):
You can’t perform that action at this time.
0 commit comments