I have this code in dodo.py
:
def closed_over(par):
print("\n??? " + par)
if par == "bar":
return False
else:
return True
def task_bug():
for par in ("foo", "bar"):
print("par: " + par)
# closure!
exist_fn = lambda: closed_over(par)
print(exist_fn)
yield {
"name": par,
"actions": [["echo", "action:", par]],
"verbosity": 2,
"uptodate": [exist_fn]
}
When I run doit bug:foo
I expect to NOT execute it as (closed_over
returns True
), but:
par: foo
<function task_bug.<locals>.<lambda> at 0x7f8926f9a560>
par: bar
<function task_bug.<locals>.<lambda> at 0x7f8926f9a5f0>
??? bar <- par should be foo
. bug:foo
action: foo <- echo was called
As you can see above the two closures outside the yield
are different function objects but for some reason uptodate
is always calling the same.