[Python-Dev] Using and binding relative names (was Re: PEP for Better Control of Nested Lexical Scopes)
steven.bethard at gmail.com
Wed Feb 22 20:41:54 CET 2006
On 2/21/06, Phillip J. Eby <pje at telecommunity.com> wrote:
> Here's a crazy idea, that AFAIK has not been suggested before and could
> work for both globals and closures: using a leading dot, ala the new
> relative import feature. e.g.:
> def incrementer(val):
> def inc():
> .val += 1
> return .val
> return inc
> The '.' would mean "this name, but in the nearest outer scope that defines
> it". Note that this could include the global scope, so the 'global'
> keyword could go away in 2.5. And in Python 3.0, the '.' could become
> *required* for use in closures, so that it's not necessary for the reader
> to check a function's outer scope to see whether closure is taking
> place. EIBTI.
FWIW, I think this is nice. Since it uses the same dot-notation that
normal attribute access uses, it's clearly accessing the attribute of
*some* namespace. It's not perfectly intuitive that the accessed
namespace is the enclosing one, but I do think it's at least more
intuitive than the suggested := operator, and at least as intuitive as
a ``global``-like declaration. And, as you mention, it's consistent
with the relative import feature.
I'm a little worried that this proposal will get lost amid the mass of
other suggestions being thrown out right now. Any chance of turning
this into a PEP?
Grammar am for people who can't think for myself.
--- Bucky Katt, Get Fuzzy
More information about the Python-Dev