How to use the makefun._main_latest_py.make_partial_using_yield_from 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 / View on Github external
if len(orig_sig.parameters) <= len(preset_pos_args):
        raise ValueError("Cannot preset %s positional args, function %s has only %s args."
                         "" % (len(preset_pos_args), f.__name__, len(orig_sig.parameters)))
    new_sig = Signature(parameters=tuple(orig_sig.parameters.values())[len(preset_pos_args):],
    # then the keyword
        new_sig = remove_signature_parameters(new_sig, *preset_kwargs.keys())
    except KeyError as e:
        raise ValueError("Cannot preset keyword argument, it does not appear to be present in the signature of %s: %s"
                         "" % (f.__name__, e))

    if _is_generator_func(f):
        if sys.version_info >= (3, 3):
            from makefun._main_latest_py import make_partial_using_yield_from
            partial_f = make_partial_using_yield_from(new_sig, f, *preset_pos_args, **preset_kwargs)
            from makefun._main_legacy_py import make_partial_using_yield
            partial_f = make_partial_using_yield(new_sig, f, *preset_pos_args, **preset_kwargs)
        @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.
            return f(*itertools.chain(preset_pos_args, args), **kwargs)

    # update the doc
    argstring = ', '.join([("%s" % a) for a in preset_pos_args])
    if len(argstring) > 0:
        argstring = argstring + ', '
    argstring = argstring + str(new_sig)[1:-1]
    if len(argstring) > 0: