2.1 strangness

Skip Montanaro skip at pobox.com
Thu May 31 14:02:51 EDT 2001


>>>>> "Robin" == Robin Becker <robin at jessikat.fsnet.co.uk> writes:

    Robin> from httplib import *

    Robin> class Bongo(HTTPConnection):
    Robin>         pass
    ...
    Robin> NameError: name 'HTTPConnection' is not defined

It was a brain fart on my part when creating httplib.__all__.
HTTPConnection was not included in that list.  I will check in a fix.
In the 2.1 release __all__ was defined as 

    __all__ = ["HTTP"]

I have changed that to

    __all__ = ["HTTP", "HTTPResponse", "HTTPConnection", "HTTPSConnection",
	       "HTTPException", "NotConnected", "UnknownProtocol",
	       "UnknownTransferEncoding", "IllegalKeywordArgument",
	       "UnimplementedFileMode", "IncompleteRead",
	       "ImproperConnectionState", "CannotSendRequest", "CannotSendHeader",
	       "ResponseNotReady", "BadStatusLine", "error"]

and will check the change into CVS shortly. (Thomas, keep an eye open for
this as an addition to 2.1.1.)

The workaround I would choose is to not use from "httplib import *":

    import httplib

    class Bongo(httplib.HTTPConnection):
        pass

    Robin> Changing the * to HTTPConnection in ttt.py removes the problem.

Yup, that will also work.

Before anyone asks, "Who died and make Skip King?", the scenario as I recall
it was that the semantics of __all__ got settled on during discussions on
python-dev (the goal of __all__ being to minimize namespace pollution by
"from ... *"), but nobody stepped up immediately to do the gtunt work, so I
volunteered.  The problem in relying on one person (well, at least this one
person) to do this was that I had only the following tools at my disposal to
decide what belonged in __all__:

    * what was documented in the lib reference manual (which was at times
      incomplete)
    * my experience with the various modules (some of which was specialized,
      some of which was nonexistent)
    * the standard library (which generally doesn't use "from ... *" much)
    * input from python-dev (whose members also appear not to use "from
      ... *" very liberally)

In retrospect, I probably should have polled c.l.py with a summary of what I
came up with before the 2.1 ship date.  If people would like me to do that
now (before 2.2 gets anywhere close to release) to try and fill in as many
missing symbols as possible, let me know.

-- 
Skip Montanaro (skip at pobox.com)
(847)971-7098




More information about the Python-list mailing list