![](https://secure.gravatar.com/avatar/abfc96478aa67b1a1887ff2bac255e05.jpg?s=120&d=mm&r=g)
"GvR" == Guido van Rossum <guido@digicool.com> writes:
The nested scopes rules don't kick in until you've got one function nested in another. The top-level namespace is treated differently that other function namespaces. If a function is defined at the top-level then all its free variables are globals. As a result, the old rules still apply.
GvR> This doesn't make sense. If the free variables were truely GvR> considered globals, the reference to x would raise a NameError, GvR> because the exec doesn't define it at the global level -- it GvR> defines it at the local level. So apparently you are GvR> generating LOAD_NAME instead of LOAD_GLOBAL for free variables GvR> in toplevel functions. Oh well, this does the job! Actually, I only generate LOAD_NAME for unoptimized, top-level function namespaces. These are exactly the old rules and I avoided changing them for top-level functions, except when they contained a nested function. If we eliminate exec without "in," this is yet another problem that goes away. Jeremy