Message24423
Logged In: YES
user_id=31392
The source of the problem is that scoping decisions are made
statically. If a variable is determined to be local at
compile time, it can't be access as a free variable in
dynamically compiled code. The compiler has already
determined that the variable is *not* free in the containing
function. If a variable is free in a nested function, the
compiler treats it differently than if it is merely local to
the function.
In the most recent cases considered,
def f(x): eval('x') -- works because x is a local variable in f.
def f(g): eval('lambda x: g(x)') -- does not work because
the compiler has determined that g is not used a free
variable in f. It isn't possible to change that static
analysis at runtime using eval or exec.
I agree that the documentation could be clearer here.
|
|
Date |
User |
Action |
Args |
2007-08-23 14:29:50 | admin | link | issue1153622 messages |
2007-08-23 14:29:50 | admin | create | |
|