nested scopes
Tim Peters
tim.one at home.com
Fri Feb 2 23:19:19 EST 2001
>> def bingo():
>> from string import *
> > ....
[John J. Lee]
> Are nested scopes actually going to end up in Python proper,
> then? As opposed to remaining as an optional patch?
They're *in* 2.1a2, released earlier today.
> And why should the above become bad rather than just import
> into the appropriate namespace?
Whether a name is local to a given scope is, in Python, determined by
whether the name is *bound* somewhere in that scope. "import *" counts as a
binding, but the compiler has no idea which names are being bound. So when
compiling code for a nested function N, referencing a non-local name (one
that is not bound to within N's body) X, the compiler has no idea which
scope X belongs to if an "import *" (or "exec" stmt) appears in an enclosing
function E. Any name whatsoever *may* become local in E then, but it's
impossible to know anything about that at compile-time.
If you still think it's easy, submit a patch <wink>.
invitation-or-threat-is-in-the-eye-of-the-beholder-ly y'rs - tim
More information about the Python-list
mailing list