[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Lib/test test___all__.py,1.3,1.4

Guido van Rossum guido@digicool.com
Wed, 24 Jan 2001 10:37:03 -0500


>     Guido> I think I saw a complaint about this that specifically said that
>     Guido> when dbhash is imported when bsddb can't be imported, an
>     Guido> incomplete dbhash is left behind in sys.modules, and then a
>     Guido> second import of dbhash will succeed -- but of course it will
>     Guido> define no objects.
> 
> So it does:
> 
>     % ./python
>     Python 2.1a1 (#2, Jan 23 2001, 23:30:41) 
>     [GCC 2.95.3 19991030 (prerelease)] on linux2
>     Type "copyright", "credits" or "license" for more information.
>     >>> import dbhash
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in ?
>       File "/home/beluga/skip/src/python/dist/src/Lib/dbhash.py", line 3, in ?
> 	import bsddb
>     ImportError: No module named bsddb
>     >>> import dbhash
>     >>>
> 
> Can that be construed as a bug?  If import fails, shouldn't the stub module
> that was inserted in sys.modules be removed?

Yep, but not a very important bug -- typically this isn't caught.
Feel free to check in a change; I think you should be able to insert
something like

    import sys
    try:
	import bsddb
    except ImportError:
	del sys.modules[__name__]
	raise

into dbhash.

If this works for you in testing, forget the patch manager, just check
it in.  (I'm too busy to do much myself, the company needs me. :-)

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