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

Function recurse_ex

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

auto-handles original *args and **kwargs. Use it like recurse_ex(myfunc,locals(),changed=changed-1)

(func, func_locals, **kwargs)

Source from the content-addressed store, hash-verified

26 return func(*args,**kwargs)
27
28def recurse_ex(func, func_locals, **kwargs):
29 """auto-handles original *args and **kwargs.
30 Use it like recurse_ex(myfunc,locals(),changed=changed-1)
31 """
32 co=func.func_code
33 args = tuple([ kwargs.pop(co.co_varnames[i], func_locals[co.co_varnames[i]])
34 for i in range(co.co_argcount) ])
35 if co.co_flags & 0x04:
36 i+=1
37 args+=func_locals[co.co_varnames[i]]
38 if co.co_flags & 0x08:
39 kwargs.update(func_locals[co.co_varnames[i+1]]) #TODO:reverse priority?
40 return func(*args,**kwargs)
41
42def recursor(func, func_locals):
43 co=func.func_code

Callers 1

func4Function · 0.85

Calls 4

rangeFunction · 0.85
funcFunction · 0.50
popMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected