[Python-ideas] A "local" pseudo-function

MRAB python at mrabarnett.plus.com
Tue May 1 13:45:34 EDT 2018


On 2018-05-01 02:52, Tim Peters wrote:
> [MRAB <python at mrabarnett.plus.com>]
> > ...
> > The intention is that only the specified names are local.
> >
> > After all, what's the point of specifying names after the 'local' if _any_
> > binding in the local scope was local?
>
> Don't look at me ;-)  In the absence of use cases, I don't know which
> problem(s) you're trying to solve.  All the use cases I've looked at
> are adequately addressed by having some spelling of "local:" change
> nothing at all about Python's current scope rules.  If you have uses
> in mind that require more than just that, I'd need to see them.
>
> >> ...
> >> If you agree that makes the feature probably unusable, you don't get
> >> off the hook by saying "no, unlike current Python scopes, binding
> >> sites have nothing to do with what's local to a new lexical scope
> >> introduced by 'local:'".  The same question raised in the example
> >> above doesn't go away:  in which scope(s) are 'r1' and 'r2' to be
> >> bound?
>
> > Any binding that's not specified as local is bound in the parent scope:
>
> Reverse-engineering the example following, is this a fair way of
> making that more precise?
>
> Given a binding-target name N in scope S, N is bound in scope T, where
> T is the closest-containing scope (which may be S itself) for which T
> is either
>
> 1. established by a "local:" block that declares name N
>
> or
>
> 2. not established by a "local: block
>
By "parent scope" I meant the function or global scope, a scope that's 
not a "local:" scope. I couldn't think of a good name for it.

[snip]



More information about the Python-ideas mailing list