This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyImport_Import calls __import__ with dummy fromlist
Type: behavior Stage: needs patch
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: belopolsky, brett.cannon
Priority: normal Keywords:

Created on 2010-07-13 21:19 by belopolsky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg110228 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-07-13 21:19
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

sys.modules.__init__(saved_sys_modules)

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__"], ..)

failed.

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>.
msg116887 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2010-09-19 21:39
Fixed in r84908.
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53498
2010-09-19 21:39:18brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg116887
2010-07-13 21:19:12belopolskycreate