How to use the makefun.main.wraps function in makefun

To help you get started, we’ve selected a few makefun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github smarie / python-makefun / makefun / _main_legacy_py.py View on Github external
    @wraps(f, new_sig=new_sig)
    def partial_f(*args, **kwargs):
        # since the signature does the checking for us, no need to check for redundancy.
        kwargs.update(preset_kwargs)
        gen = f(*chain(preset_pos_args, args), **kwargs)
        _i = iter(gen)  # initialize the generator
        _y = next(_i)  # first iteration
        while 1:
            try:
                _s = yield _y  # yield the first output and retrieve the new input
            except GeneratorExit as _e:  # ---generator exit error---
                try:
                    _m = _i.close  # if there is a close method
                except AttributeError:
                    pass
                else:
                    _m()  # use it first