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.

Author Arfrever
Recipients Arfrever, eli.bendersky, flox
Date 2012-06-03.07:21:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1338708115.99.0.275881966348.issue14988@psf.upfronthosting.co.za>
In-reply-to
Content
If, after building of Python, libexpat.so (library used by pyexpat module) has been broken/removed or pyexpat module has been broken/removed, then attempt of import of _elementtree module, which requires pyexpat module, will raise strange exceptions in Python 3.

These exceptions can be simulated by setting sys.modules["pyexpat"] = None.

$ python2.6 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pyexpat
$ python2.7 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: PyCapsule_Import could not import module "pyexpat"
$ python3.1 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
SystemError: initialization of _elementtree raised unreported exception
$ python3.2 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
SystemError: initialization of _elementtree raised unreported exception
$ python3.3 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1286, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1253, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 432, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 347, in set_package_wrapper
  File "<frozen importlib._bootstrap>", line 360, in set_loader_wrapper
  File "<frozen importlib._bootstrap>", line 870, in load_module
RuntimeError: cannot load dispatch table from pyexpat

I suggest to raise ImportError instead of SystemError or RuntimeError.
Third-party modules would rather use only 'except ImportError: pass' instead of 'except (ImportError, SystemError, RuntimeError): pass' when trying to optionally use e.g. xml.etree.cElementTree.
xml.etree.ElementTree in Python 3.3 also ignores only ImportError when trying to import _elementtree.
History
Date User Action Args
2012-06-03 07:21:56Arfreversetrecipients: + Arfrever, eli.bendersky, flox
2012-06-03 07:21:55Arfreversetmessageid: <1338708115.99.0.275881966348.issue14988@psf.upfronthosting.co.za>
2012-06-03 07:21:55Arfreverlinkissue14988 messages
2012-06-03 07:21:54Arfrevercreate