classification
Title: imp.load_module won't accept None for the file argument for a C extension
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: Arfrever, brett.cannon, eric.snow, georg.brandl, larry, ncoghlan, paul.moore, python-dev
Priority: release blocker Keywords: 3.3regression

Created on 2012-09-10 12:04 by paul.moore, last changed 2013-05-12 09:41 by georg.brandl. This issue is now closed.

Messages (7)
msg170178 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2012-09-10 12:04
imp.load_module appears to have a regression - the file argument is not allowed to be None when loading a C_EXTENSION. The pywin32 post-install script for version 217 calls imp.load_module for a C extension with file=None, so presumably this worked in earlier versions.

Note that apparently pywin32 tip no longer calls load_module in this way, and load_module is marked as deprecated in the documentation, so it is not clear if this issue actually needs fixing.

See #15828 for some background.
msg170185 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-09-10 13:01
How can you load a C extension without a file path? Are C extensions being inappropriately flagged as built-in modules on Windows? What does imp.find_module() return for the module being checked? I need more debugging info on what imp.find_module() and imp.load_module() returns in 3.2 and 3.3 before I can make a call on where the actual breakage is.
msg170186 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2012-09-10 13:03
It's the open file object argument, not the path. I assume that if you
supplied None, the code opened the file for you.
msg170198 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-09-10 16:04
Well, that's extremely annoying as that doesn't work for .py or .pyc files::

>>> import imp
>>> stuff = imp.find_module('blah')
>>> stuff
(<_io.TextIOWrapper name=4 mode='U' encoding='utf-8'>, 'blah.py', ('.py', 'U', 1))
>>> stuff[0].close()
>>> imp.load_module('blah', None, 'blah.py', stuff[2])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: file object required for import (type code 1)

I really hate these functions.
msg188302 - (view) Author: Roundup Robot (python-dev) Date: 2013-05-03 14:47
New changeset c0a21617dbee by Brett Cannon in branch '3.3':
Issue #15902: Fix imp.load_module() to accept None as a file when
http://hg.python.org/cpython/rev/c0a21617dbee

New changeset 322c556260d5 by Brett Cannon in branch 'default':
#15902: merge w/ 3.3
http://hg.python.org/cpython/rev/322c556260d5
msg188308 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-05-03 17:13
Leaving it up to the release manager to decide if this is worth cherrypicking or just waiting for the next bugfix release.
msg188440 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-05-05 12:42
http://hg.python.org/cpython/rev/996a937cdf81 also applies to this.
History
Date User Action Args
2013-05-12 09:41:35georg.brandlsetstatus: open -> closed
2013-05-05 12:42:10brett.cannonsetmessages: + msg188440
2013-05-03 17:16:17brett.cannonsetnosy: brett.cannon, georg.brandl, paul.moore, ncoghlan, larry, Arfrever, python-dev, eric.snow
2013-05-03 17:13:41brett.cannonsetstatus: closed -> open
priority: normal -> release blocker

nosy: + larry
messages: + msg188308
2013-05-03 14:53:18brett.cannonsetstatus: open -> closed
stage: resolved
resolution: fixed
versions: + Python 3.4
2013-05-03 14:47:27python-devsetnosy: + python-dev
messages: + msg188302
2013-03-26 18:08:02brett.cannonsetassignee: brett.cannon
2012-09-10 19:23:02Arfreversetnosy: + Arfrever
2012-09-10 16:04:19brett.cannonsetnosy: + eric.snow
2012-09-10 16:04:02brett.cannonsetmessages: + msg170198
2012-09-10 13:03:23paul.mooresetstatus: pending -> open

messages: + msg170186
2012-09-10 13:01:50brett.cannonsetstatus: open -> pending

messages: + msg170185
2012-09-10 12:04:49paul.moorecreate