diff options
author | Brett Cannon <brett@python.org> | 2013-05-03 14:37:08 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-05-03 14:37:08 (GMT) |
commit | 9d0f772c5115217d55aef76fae33f483f2a98032 (patch) | |
tree | a9cf061e4964455f440db0d4a074ff167fef5837 /Lib/imp.py | |
parent | b98dcc1f5307789c3c42af701f81147e240b90ff (diff) | |
download | cpython-9d0f772c5115217d55aef76fae33f483f2a98032.zip cpython-9d0f772c5115217d55aef76fae33f483f2a98032.tar.gz cpython-9d0f772c5115217d55aef76fae33f483f2a98032.tar.bz2 |
Issue #15902: Fix imp.load_module() to accept None as a file when
trying to load an extension module.
While at it, also add a proper unittest.skipIf() guard to another test
involving imp.load_dynamic().
Diffstat (limited to 'Lib/imp.py')
-rw-r--r-- | Lib/imp.py | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -168,7 +168,7 @@ def load_module(name, file, filename, details): warnings.simplefilter('ignore') if mode and (not mode.startswith(('r', 'U')) or '+' in mode): raise ValueError('invalid file open mode {!r}'.format(mode)) - elif file is None and type_ in {PY_SOURCE, PY_COMPILED, C_EXTENSION}: + elif file is None and type_ in {PY_SOURCE, PY_COMPILED}: msg = 'file object required for import (type code {})'.format(type_) raise ValueError(msg) elif type_ == PY_SOURCE: @@ -176,7 +176,11 @@ def load_module(name, file, filename, details): elif type_ == PY_COMPILED: return load_compiled(name, filename, file) elif type_ == C_EXTENSION and load_dynamic is not None: - return load_dynamic(name, filename, file) + if file is None: + with open(filename, 'rb') as opened_file: + return load_dynamic(name, filename, opened_file) + else: + return load_dynamic(name, filename, file) elif type_ == PKG_DIRECTORY: return load_package(name, filename) elif type_ == C_BUILTIN: |