Message144636
I'll take a shot and writing a patch for this one. Nick, are the
elements in 'co_freevars' and '__closures__' always expected to match
up? In other words, is the 'closure' function below always expected to
work (simplified; no error checking):
>>> def make_adder(x):
... def add(y):
... return x + y
... return add
...
>>> def curry(func, arg1):
... return lambda arg2: func(arg1, arg2)
...
>>> def less_than(a, b):
... return a < b
...
>>> greater_than_five = curry(less_than, 5)
>>> def closure(func):
... vars = [var for var in func.__code__.co_freevars]
... values = [cell.cell_contents for cell in func.__closure__]
... return dict(zip(vars, values))
...
>>> inc = make_adder(1)
>>> print(closure(inc))
{'x': 1}
>>> print(closure(greater_than_five))
{'arg1': 5, 'func': <function less_than at 0xb74c6924>}
? |
|
Date |
User |
Action |
Args |
2011-09-29 20:40:31 | meador.inge | set | recipients:
+ meador.inge, ncoghlan, Yury.Selivanov, eric.snow |
2011-09-29 20:40:31 | meador.inge | set | messageid: <1317328831.51.0.156802651703.issue13062@psf.upfronthosting.co.za> |
2011-09-29 20:40:30 | meador.inge | link | issue13062 messages |
2011-09-29 20:40:30 | meador.inge | create | |
|