[Python-Dev] Document None values in sys.modules?

Brett Cannon brett at python.org
Fri Jul 24 04:31:24 CEST 2009


On Thu, Jul 23, 2009 at 13:05, Guido van Rossum <guido at python.org> wrote:

> On Thu, Jul 23, 2009 at 12:09 PM, Fred Drake<fdrake at acm.org> wrote:
> > On Jul 23, 2009, at 2:59 PM, Georg Brandl wrote:
> >>
> >> is the presence of None values in sys.modules considered an
> implementation
> >> detail?  If not, it should be documented what the None values mean to
> the
> >> interpreter.
> >
> > As I recall, they're an optimization.  But since sys.modules is itself
> > documented, and many applications actually use it, I think it's worth
> > explaining that the None values can reasonably be expected, and what they
> > indicate.
>
> They should certainly be documented -- without them imports from
> inside package would be super expensive (at least for Python versions
> where implicit relative import exists). I'm somewhat surprised this
> isn't documented, I don't think I've tried to keep this usage hidden.
> I've also sometimes abused this to force some module to believe that a
> certain other module doesn't exist.
>

It has not been hidden, but the only place I ever came across it was in the
original essay about packages.


>
> OTOH in Py3k I'm not sure that we even *need* them any more, since
> there is no more implicit relative import... They would only speed up
> the raising of ImportError, not the finding of a similar-named module
> elsewhere in the hierarchy.


None in Python 3.1 is really useless in terms of its semantics in relative
imports; importlib doesn't support it and still passes as __import__ (at
least last time I ran the test suite that way). I thought we had agreed a
while back that supporting None was not warranted in Python 3.0? Otherwise I
will do whatever work is necessary for this to happen.

-Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090723/961093cc/attachment.htm>


More information about the Python-Dev mailing list