@@ -33,6 +33,13 @@ def iscoroutinefunction(f):
3333 def isgeneratorfunction (f ):
3434 return False
3535
36+ try :
37+ from inspect import isasyncgenfunction
38+ except ImportError :
39+ # assume no generator function in old Python versions
40+ def isasyncgenfunction (f ):
41+ return False
42+
3643try : # python 3.5+
3744 from typing import Callable , Any , Union , Iterable , Dict , Tuple , Mapping
3845except ImportError :
@@ -246,6 +253,8 @@ def create_function(func_signature, # type: Union[str, Signature]
246253 else :
247254 from makefun ._main_legacy_py import get_legacy_py_generator_body_template
248255 body = get_legacy_py_generator_body_template () % (func_signature_str , params_str )
256+ elif isasyncgenfunction (func_impl ):
257+ body = "async def %s\n async for y in _func_impl_(%s):\n yield y\n " % (func_signature_str , params_str )
249258 else :
250259 body = "def %s\n return _func_impl_(%s)\n " % (func_signature_str , params_str )
251260
@@ -1123,6 +1132,9 @@ def partial(f, # type: Callable
11231132 else :
11241133 from makefun ._main_legacy_py import make_partial_using_yield
11251134 partial_f = make_partial_using_yield (new_sig , f , * preset_pos_args , ** preset_kwargs )
1135+ elif isasyncgenfunction (f ) and sys .version_info >= (3 , 6 ):
1136+ from makefun ._main_latest_py import make_partial_using_async_for_in_yield
1137+ partial_f = make_partial_using_async_for_in_yield (new_sig , f , * preset_pos_args , ** preset_kwargs )
11261138 else :
11271139 @wraps (f , new_sig = new_sig )
11281140 def partial_f (* args , ** kwargs ):
0 commit comments