[Python-Dev] Those import related syntax errors again...

Samuele Pedroni Samuele Pedroni <pedroni@inf.ethz.ch>
Wed, 21 Feb 2001 17:33:02 +0100 (MET)


Hi.

[Fredrik Lundh]
> 
> Samuele wrote:
> > On the other hand just saying that new feature X make code Y (previously 
valid)
> > meaningless and so the unique solution is to discard Y as garbage,
> > is something that cannot be sold for cheap. I have the feeling that this
> > is the *point*.
> 
> exactly.
> 
> I don't mind new features if I can chose to ignore them...

Along this line of thought and summarizing:

- import * (in an inner scope) is somehow a problem but on the long run it 
should be likely deprecated and become an error anyway.
- mixing of inner defs or lambdas and exec is a real issue
(Mark Hammond original posting was caused but such a situation):
 for that there is no clear workaround: I repeat 
 
y=3
def f():
 exec "y=2"
 def g()
   return y
 return g()

if we want 2 as return value it's a mess (the problem could end up being
more perfomance than complexity, altough simple impl is a long-run win).
Developing special rules is also not that simple: just put an y = 9
before the exec, what is expected then? This promises lot of confusion.

- I'm not a partisan of this, but if we want to able 
 to "choose to ignore" lexical scoping, we will need to make
 its activation explicit. 
but this has been discarded, so no story...

Implicit scoping semantic has been changed  and now we just have to convince
ourself that this is a win, and there is no big code breakage (this is very 
likely, without irony)
and that transforming working code (I'm referring to code using 'exec's not 
import *) in invalid code is just natural language evolution 
that users will understand <wink>.

We can make the transition more smooth:
[Andrew Kuchling]
> >IMO breaking code would be ok if we issue warnings today and implement
> >nested scopes issuing errors tomorrow. But this is simply a statement
> >about principles and raised impression.
> 
> Agreed.  So maybe that's the best solution: pull nested scopes from
> 2.1 and add a warning for from...import (and exec?) inside a function
> using nested scopes, and only add nested scopes in 2.2, after everyone
> has had 6 months or a year to fix their code.

But the problem with exec will remain.

PS: to be honest the actual impl of nested scope is fine for me from the
viewpoint of the guy that should implement that for jython ;).