Re: block scope?
Aahz <aahz@pythoncra ft.comwrote:
option 1: that just runs the compiler a bit later -- thus transforming
ClashingVariabl eError into a runtime issue, exactly like it already does
for SyntaxError.
option 2: since a function containing any exec statement does not
benefit from the normal optimization of local variables, let it also
forgo the normal diagnosis of shadowed/clashing names.
option 3: extend the already-existing prohibition of mixing exec with
nested functions:
.... def inner(): return x
.... exec('x=23')
.... return inner()
....
File "<stdin>", line 3
SyntaxError: unqualified exec is not allowed in function 'outer' it
contains a nested function with free variables
to prohibit any mixing of exec and nested functions (not just those
cases where the nested function has free variables).
My personal favorite is option 3.
Alex
Aahz <aahz@pythoncra ft.comwrote:
In article <1hw7kzo.1hepj3 c1who5zhN%aleax @mac.com>,
Alex Martelli <aleax@mac.comw rote:
>
exec?
Alex Martelli <aleax@mac.comw rote:
Steve Holden <steve@holdenwe b.comwrote:
What problems do you have in mind? The compiler already determines the
set of names that are local variables for a function; all it needs to do
is diagnose an error or warning if the set of names for a nested
function overlaps with that of an outer one.
>
What do you think the chances are of this being accepted for Python 3.0?
It is indeed about the most rational approach, though of course it does
cause problems with dynamic namespaces.
What do you think the chances are of this being accepted for Python 3.0?
It is indeed about the most rational approach, though of course it does
cause problems with dynamic namespaces.
set of names that are local variables for a function; all it needs to do
is diagnose an error or warning if the set of names for a nested
function overlaps with that of an outer one.
exec?
ClashingVariabl eError into a runtime issue, exactly like it already does
for SyntaxError.
option 2: since a function containing any exec statement does not
benefit from the normal optimization of local variables, let it also
forgo the normal diagnosis of shadowed/clashing names.
option 3: extend the already-existing prohibition of mixing exec with
nested functions:
>>def outer():
.... exec('x=23')
.... return inner()
....
File "<stdin>", line 3
SyntaxError: unqualified exec is not allowed in function 'outer' it
contains a nested function with free variables
to prohibit any mixing of exec and nested functions (not just those
cases where the nested function has free variables).
My personal favorite is option 3.
Alex
Comment