MCPcopy Create free account
hub / github.com/ActiveState/code / recurse

Function recurse

recipes/Python/491265_Automatic_Recursion/recipe-491265.py:20–26  ·  view source on GitHub ↗

for ad-hoc recursion - in case: manual insertion of original *args/**kwargs. Use it like recurse(myfunc,locals(),changed=changed-1,*args,**kwargs)

(func, func_locals, *args, **kwargs)

Source from the content-addressed store, hash-verified

18 assert not kwargs
19
20def recurse(func, func_locals, *args, **kwargs):
21 """for ad-hoc recursion - in case: manual insertion of original *args/**kwargs.
22 Use it like recurse(myfunc,locals(),changed=changed-1,*args,**kwargs)"""
23 co=func.func_code
24 args = tuple([ kwargs.pop(co.co_varnames[i], func_locals[co.co_varnames[i]])
25 for i in range(co.co_argcount) ]) + args
26 return func(*args,**kwargs)
27
28def recurse_ex(func, func_locals, **kwargs):
29 """auto-handles original *args and **kwargs.

Callers 2

func1Function · 0.70
methMethod · 0.70

Calls 3

rangeFunction · 0.85
funcFunction · 0.50
popMethod · 0.45

Tested by

no test coverage detected