[Python-ideas] binding vs rebinding
dangyogi at gmail.com
Thu Feb 5 15:59:45 CET 2009
> It seems that if ever the second step would not hold, then there would be no reason for such declarations. Imagine that rebinbing is spellt using ':='. Then, from a non-glocal scope:
> * a=1 causes creation of a local name
> * a:=1 rebinds a local name if exists, or rebinds an external name if exists (step-by-step up to module level scope), or else launches NameError.
> There may be reasons why such a behaviour is not the best a programmer would expect: I wait for your comments.
I like the idea.
On the global/nonlocal thing, it would be possible that a nested
function does a:=l and there is both a nonlocal "a" and a global "a".
The current global/nonlocal mechanism allows the programmer to
disambiguate this case. But it is hard to imagine use cases where this
couldn't be resolved by renaming one of the "a" variables. And the same
problem occurs in the current mechanism where a function nested 2 levels
down has two nonlocal "a" variables: in its direct parent, and in its
More information about the Python-ideas