[Python-checkins] r52926 - sandbox/trunk/import_in_py/importer.py sandbox/trunk/import_in_py/test_importer.py
brett.cannon
python-checkins at python.org
Wed Dec 6 01:22:39 CET 2006
Author: brett.cannon
Date: Wed Dec 6 01:22:38 2006
New Revision: 52926
Modified:
sandbox/trunk/import_in_py/importer.py
sandbox/trunk/import_in_py/test_importer.py
Log:
If a .pyc file has bad bytecode for a code object, ImportError is raised even if a completely valid source file is present.
Modified: sandbox/trunk/import_in_py/importer.py
==============================================================================
--- sandbox/trunk/import_in_py/importer.py (original)
+++ sandbox/trunk/import_in_py/importer.py Wed Dec 6 01:22:38 2006
@@ -28,7 +28,8 @@
XXX Semantics
=============
-* If bad bytecode in .pyc but good source, is source used and bytecode recreated?
+* Frozen packages.
+* Case-insensitive filesystems.
Things to be exposed at the Python level
@@ -498,6 +499,10 @@
try:
code_object = self.code_from_bytecode(bytecode)
except ValueError:
+ # Since bad bytecode halts the import entirely having the
+ # source code is useless. Use this fact to signal that
+ # the ImportError being raised should propagate.
+ source_path = None
raise ImportError('Non-code object in %s' %
str(bytecode_path))
exec code_object in module.__dict__
@@ -557,7 +562,6 @@
files). Both are controlled during instance initialization.
"""
- # XXX Import lock not used.
def __init__(self, default_path_hook=None,
extended_meta_path=(BuiltinImporter, FrozenImporter)):
Modified: sandbox/trunk/import_in_py/test_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/test_importer.py (original)
+++ sandbox/trunk/import_in_py/test_importer.py Wed Dec 6 01:22:38 2006
@@ -646,8 +646,11 @@
self.failUnless("write_data" in loader.log)
def test_bad_bytecode_w_py(self):
- # XXX Will the bytecode be recreated?
- pass
+ # Even when there is a valid .py file, if the .pyc file has bad bytecode
+ # ImportError is raised.
+ loader = mock_importer.MockPyPycLoader.setup(good_bytecode=False)
+ handler = loader._create_handler(importer.PyPycHandler)
+ self.failUnlessRaises(ImportError, loader._handle_pyc, handler)
def test_py_no_pyc(self):
# Test importing a .py file where no .pyc path is available.
More information about the Python-checkins
mailing list