Richard Jones (who isn't subscribed to this list, else he'd be sending this message himself) would like it pointed out that the "withhacks" module does some things very similar to this (by using bytecode hackery, IIUC). See especially the xkwargs and xargs functions.
from withhacks import xkwargs print(xkwargs.__doc__)
WithHack calling a function with extra keyword arguments.
This WithHack captures any local variables created during execution of the block, then calls the given function using them as extra keyword arguments.
>>> def calculate(a,b): ... return a * b ... >>> with xkwargs(calculate,b=2) as result: ... a = 5 ... >>> print result 10