[Python-Dev] Showstopper in import?

M.-A. Lemburg mal@lemburg.com
Fri, 02 Feb 2001 11:08:16 +0100


Tim Peters wrote:
> 
> [M.-A. Lemburg]
> > I have already reported this to Jeremy. There are other instances
> > of 'from x import *' in function and class scope too, e.g.
> > some test() functions in the standard dist do this.
> 
> But there are no instances of "from x import *" in the case I reported,
> despite that the error msg (erroneously!) claimed there was.  It's
> complaining about
> 
>     from Percolator import Percolator
> 
> in a class definition.  That smells like a bug, not a debatable design
> choice.

Percolator has "from x import *" code. This is what is causing the
exception. I think it has already been fixed in CVS though, so should
work again.
 
> > I am repeating myself here, but I think that this single change
> > will cause so many people to find their scripts are failing
> > that it is really not worth it.
> 
> Provided the case above is fixed, IDLE will indeed fail to compile anyway,
> because Guido does
> 
>     from Tkinter import *
> 
> inside several functions.  But that's a different problem.

How is it different ? 

Even though I agree that "from x import *"
is bad style, it is quite common in testing code or code
which imports a set of symbols from generated modules or
modules containing only constants e.g. for protocols, error
codes, etc.
 
> > Better issue a warning than raise an exception here !
> 
> If Jeremy can't generate correct code, a warning is too weak.

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

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company:                                        http://www.egenix.com/
Consulting:                                    http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/