How to use the makefun._main_legacy_py.make_partial_using_yield 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.py View on Github external
new_sig = Signature(parameters=tuple(orig_sig.parameters.values())[len(preset_pos_args):],
                        return_annotation=orig_sig.return_annotation)
    # then the keyword
    try:
        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)
        else:
            from makefun._main_legacy_py import make_partial_using_yield
            partial_f = make_partial_using_yield(new_sig, f, *preset_pos_args, **preset_kwargs)
    else:
        @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)
            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:
        argstring = argstring + ', '
    argstring = argstring + ', '.join(["%s=%s" % (k, v) for k, v in preset_kwargs.items()])