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

Guido van Rossum guido at python.org
Thu Jul 23 22:05:51 CEST 2009


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.

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.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list