2.1 strangness

Remco Gerlich scarblac at pino.selwerd.nl
Fri Jun 1 01:26:37 EDT 2001


Andreas Jung <andreas at andreas-jung.com> wrote in comp.lang.python:
> 
> "Robin Becker" <robin at jessikat.fsnet.co.uk> schrieb im Newsbeitrag
> news:lCoIXKAB3mF7Ew5A at jessikat.demon.co.uk...
> > This is a condensation of some weirds I'm seeing with M2Crypto which I
> > downloaded today; I'm running SF 2.1 for win32
> >
> > ##################################
> > #file ttt.py
> > from httplib import *
> >
> > class Bongo(HTTPConnection):
> >         pass
> > ##################################
> >
> > when I attempt to run this
> >
> > C:\Python\devel\m2crypto-0.06-snap5-win32\demo\ssl>python \tmp\ttt.py
> > Traceback (most recent call last):
> >   File "\tmp\ttt.py", line 3, in ?
> >     class Bongo(HTTPConnection):
> > NameError: name 'HTTPConnection' is not defined
> >
> > but certainly httplib has a class HTTPConnection
> >
> > is this the famous blow up in your face from the future concerning
> > shadowed globals? It seems rather nasty to me, but then I objected to
> > the original static scoping stuff. This seems entirely module level so
> > what gives?
> 
> Your "from httplib import *" is the problem. Since Python 2.1 (?) only
> elements definied in module.__all__ will be imported by 'import *'.

If module.__all__ is defined. If it's not, you get the old behaviour
(just clarifying).

> httplib.__all__ is ['HTTP']. 

If you look at the library reference, all the module does is define the HTTP
class anyway. The rest is implementation detail that may change, apparently.

On the other hand, it's irritating that things that used to be imported with
a 'from import *' aren't anymore. The old mechanism was that names that
shouldn't be imported had prefix _; there are a few of those in httplib. Why
does it suddenly have an __all__ that contains only HTTP?

-- 
Remco Gerlich




More information about the Python-list mailing list