[Python-Dev] Showstopper in import?

Jeremy Hylton jeremy@alum.mit.edu
Fri, 2 Feb 2001 10:51:26 -0500 (EST)


  MAL> Better issue a warning than raise an exception here !

  TP> If Jeremy can't generate correct code, a warning is too weak.

  MAL> So this is the price we pay for having nested scopes... :-(

  TP> I don't know.  It apparently is the state of the code at this
  TP> instant.

The code is complaining about 'from ... import *' with nested scopes,
because of a potential ambiguity:

def f():
    from string import *
    def g(s):
        return strip(s)

It is unclear whether this code intends to use a global named strip or
to the name strip defined in f() by 'from string import *'.

It is possible, I'm sure, to complain about only those cases where
free variables exist in a nested scope and 'from ... import *' is
used.  I don't know if I will be able to modify the compiler so it
complains about *only* these cases in time for 2.1a2.

Jeremy