the demise of 'from foo import * and its implications?

Tim Peters tim.one at home.com
Fri Mar 2 18:06:25 EST 2001


[Tim]
> What gave you the idea that "import *" is going away?

[Sean 'Shaleh' Perry]
> /me needs to take a week off apparently.  Either that or stop believing
> anything he reads.
>
> I would have SWORN I read it here, and a fellow python hacker said
> something to that affect as well.

Oh, that.  That's just people panicking.  Don't listen to people -- they're
always wrong <wink>.  Here's an item from the 2.1b1 NEWS file, which you can
pick up from the 2.1b1 release later today:

  - Using "from...import *" or "exec" without in-clause in a function
    scope that also defines a lambda or nested function with one or
    more free (non-local) variables.  The presence of the import* or
    bare exec makes it impossible for the compiler to determine the
    exact set of local variables in the outer scope, which makes it
    impossible to determine the bindings for free variables in the
    inner scope.  To avoid the warning about import *, change it into
    an import of explicitly name object, or move the import* statement
    to the global scope; to avoid the warning about bare exec, use
    exec...in... (a good idea anyway -- there's a possibility that
    bare exec will be deprecated in the future).

So, yes, by the time 2.2 rolls around,

    using "from ... import *" in a
         function scope that also contains a
             lambda or nested function
                definition
                whose body contains at least one free variable
    will go away.

It's quite an ambitious act of compression to read that as "import * is going
away" <wink>.  And, according to the Reference Manual, "import *" at other
than module scope has never been legitimate (nested functions or not).

There's been no hint that import* will ever go away at module scope, despite
that it's excellent advice to avoid it whenever *reasonably* possible.
Binding to massive, flat systems (like windowing toolkits) can make avoiding
it unreasonable.

> Whichever, I will promptly use a gag as I am just digging myself a hole
> today.

Holes are comfy!  Take in a blanket and some lavender eye pillows.  import*
will still be here when you come out again <wink>.

jealously y'rs  - tim





More information about the Python-list mailing list