[New-bugs-announce] [issue9252] PyImport_Import calls __import__ with dummy fromlist

Alexander Belopolsky report at bugs.python.org
Tue Jul 13 23:19:13 CEST 2010

New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:

I have discovered this issue while working on the unit tests for issue 7989. In the first version of the setUp/tearDown overrides, I made a mistake when restoring sys.modules after the test run.  The fix was to do


instead of

sys.modules = saved_sys_modules

Interestingly, _pickle.c and pickle.py behaved differently when sys.modules was restored incorrectly:  pickle.py, using

__import__(name, ..)
mod = sys.modules[name]

picked up the incorrectly restored sys.modules, while _pickle.c, using PyImport_Import, which is effectively

mod = __import__(name, fromlist=["__doc__"], ..)


>From discussion on python-dev [1], I realize that pickle.py approach is the correct one even though in my case it would probably mask an error in my code.

At the minimum, I think _pickle.c and pickle.py should be changed to do the same thing - probably call importlib.import_module(..).  I don't know whether PyImport_Import should be fixed or deprecated.

[1] "Peculiar import code in pickle.py" <http://mail.python.org/pipermail/python-dev/2010-July/101906.html>.

assignee: brett.cannon
components: Interpreter Core
messages: 110228
nosy: belopolsky, brett.cannon
priority: normal
severity: normal
stage: needs patch
status: open
title: PyImport_Import calls __import__ with dummy fromlist
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list