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)
| 18 | assert not kwargs |
| 19 | |
| 20 | def 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 | |
| 28 | def recurse_ex(func, func_locals, **kwargs): |
| 29 | """auto-handles original *args and **kwargs. |