Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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):],
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: