Coverage for src/makefun/_main_py35_and_higher.py: 100%
7 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-09-26 12:39 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-09-26 12:39 +0000
1# Authors: Sylvain MARIE <sylvain.marie@se.com>
2# + All contributors to <https://github.com/smarie/python-makefun>
3#
4# License: 3-clause BSD, <https://github.com/smarie/python-makefun/blob/master/LICENSE>
5from itertools import chain
7from makefun.main import wraps
10def make_partial_using_yield_from(new_sig, f, *preset_pos_args, **preset_kwargs):
11 """
12 Makes a 'partial' when f is a generator and python is new enough to support `yield from`
14 :param new_sig:
15 :param f:
16 :param presets:
17 :return:
18 """
19 @wraps(f, new_sig)
20 def partial_f(*args, **kwargs):
21 # since the signature does the checking for us, no need to check for redundancy.
22 kwargs.update(preset_kwargs) # for python 3.4: explicit dict update
23 yield from f(*chain(preset_pos_args, args), **kwargs)
24 return partial_f